P
penwater191
Unregistered / Unconfirmed
GUEST, unregistred user!
程序流程:客户端点击BUTTON1后,服务器发送图片过来;
服务器端:(发送截取的屏幕图象到客户端)
procedure ScreenCap(LeftPos,TopPos,RightPos,BottomPos:integer);//截取屏幕图象
begin
bmpstream := Tmemorystream.Create;
RectWidth:=RightPos-LeftPos;
RectHeight:=BottomPos-TopPos;
SourceDC:=CreateDC('DISPLAY','','',nil);
DestDC:=CreateCompatibleDC(SourceDC);
Bhandle:=CreateCompatibleBitmap(SourceDC,RectWidth,RectHeight);
SelectObject(DestDC,Bhandle);
BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,LeftPos,TopPos,SRCCOPY);
Bitmap:=TBitmap.Create;
Bitmap.Handle:=BHandle;
BitMap.SaveToStream(BmpStream);
BmpStream.Position:=0;
LeftSize:=BmpStream.Size;
Bitmap.Free;
DeleteDC(DestDC);
ReleaseDC(Bhandle,SourceDC);
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
buf:string;
begin
if socket.ReceiveText='ft' then
begin
w:=screen.Width;
h:=screen.Height;
screencap(0,0,w,h);
Socket.SendStream(bmpstream);
end;
end;
客户端:
procedure TForm1.Button1Click(Sender: TObject);
begin
clientsocket1.Socket.SendText('ft');
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;Socket: TCustomWinSocket);
var
buf:string;
begin
stream:=tmemorystream.create;
changdu:=Socket.ReceiveLength;
buf:=socket.ReceiveText;
stream.Position:=0;
stream.WriteBuffer(buf,changdu);
form1.AutoSize:=true;
form1.Align:=alclient;
image1.Stretch:=true;
image1.Align:=alclient;
image1.AutoSize:=true;
image1.Picture.Bitmap.LoadFromStream(stream);
edit1.Text:=inttostr(changdu);//写这行代码主要是为了验证是否传过来了图片
end;
服务器端:(发送截取的屏幕图象到客户端)
procedure ScreenCap(LeftPos,TopPos,RightPos,BottomPos:integer);//截取屏幕图象
begin
bmpstream := Tmemorystream.Create;
RectWidth:=RightPos-LeftPos;
RectHeight:=BottomPos-TopPos;
SourceDC:=CreateDC('DISPLAY','','',nil);
DestDC:=CreateCompatibleDC(SourceDC);
Bhandle:=CreateCompatibleBitmap(SourceDC,RectWidth,RectHeight);
SelectObject(DestDC,Bhandle);
BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,LeftPos,TopPos,SRCCOPY);
Bitmap:=TBitmap.Create;
Bitmap.Handle:=BHandle;
BitMap.SaveToStream(BmpStream);
BmpStream.Position:=0;
LeftSize:=BmpStream.Size;
Bitmap.Free;
DeleteDC(DestDC);
ReleaseDC(Bhandle,SourceDC);
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
buf:string;
begin
if socket.ReceiveText='ft' then
begin
w:=screen.Width;
h:=screen.Height;
screencap(0,0,w,h);
Socket.SendStream(bmpstream);
end;
end;
客户端:
procedure TForm1.Button1Click(Sender: TObject);
begin
clientsocket1.Socket.SendText('ft');
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;Socket: TCustomWinSocket);
var
buf:string;
begin
stream:=tmemorystream.create;
changdu:=Socket.ReceiveLength;
buf:=socket.ReceiveText;
stream.Position:=0;
stream.WriteBuffer(buf,changdu);
form1.AutoSize:=true;
form1.Align:=alclient;
image1.Stretch:=true;
image1.Align:=alclient;
image1.AutoSize:=true;
image1.Picture.Bitmap.LoadFromStream(stream);
edit1.Text:=inttostr(changdu);//写这行代码主要是为了验证是否传过来了图片
end;