L
lihan
Unregistered / Unconfirmed
GUEST, unregistred user!
我编了一条远程抓屏的程序,但不知道为什么只能抓一次,如果再抓,在服务器端
就什么也没有显示,高手们快帮我看看
客户端的程序如下:
var
Form1: TForm1;
dc:hdc;
fullscreen:tbitmap;
fullscreencanvas:tcanvas;
smem:tmemorystream;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
application.showmainform:=false;
smem:=tmemorystream.Create;
fullscreen:=tbitmap.Create;
fullscreen.Width:=screen.Width;
fullscreen.height:=screen.height;
fullscreencanvas:=tcanvas.create;
dc:=getdc(0);
fullscreencanvas.handle:=dc;
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
if socket.ReceiveText='getpic' then
begin
fullscreen.canvas.CopyRect(rect(0,0,screen.width,screen.height),fullscreencanvas,rect(0,0,screen.width,screen.height));
image1.picture.Bitmap:=fullscreen;
image1.width:=fullscreen.Width;
image1.height:=fullscreen.height;
image1.Picture.Bitmap.SaveToStream(smem);
smem.Position:=0;
socket.SendStream(smem);
end;
end;
end.
服务器端程序如下:
var
Form1: TForm1;
rmem:tmemorystream; //接收流
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
rmem:=tmemorystream.Create;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
rlen:integer; //接收的长度
bitmap:tbitmap; //接收的图片
buf:array[0..100000] of byte; //接收的长度
begin
rlen:=Socket.ReceiveLength;
Socket.ReceiveBuf(buf,rlen);
rmem.Write(buf,rlen);
rmem.Position:=0;
bitmap:=tbitmap.Create;
bitmap.LoadFromStream(rmem);
image1.Picture.Bitmap.Assign(bitmap);
//rmem.clear;如果我加上这句就会出错
end;
procedure TForm1.Button1Click(Sender: TObject);//按下就会抓屏
begin
ServerSocket1.Socket.Connections[0].SendText('getpic');
end;
就什么也没有显示,高手们快帮我看看
客户端的程序如下:
var
Form1: TForm1;
dc:hdc;
fullscreen:tbitmap;
fullscreencanvas:tcanvas;
smem:tmemorystream;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
application.showmainform:=false;
smem:=tmemorystream.Create;
fullscreen:=tbitmap.Create;
fullscreen.Width:=screen.Width;
fullscreen.height:=screen.height;
fullscreencanvas:=tcanvas.create;
dc:=getdc(0);
fullscreencanvas.handle:=dc;
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
if socket.ReceiveText='getpic' then
begin
fullscreen.canvas.CopyRect(rect(0,0,screen.width,screen.height),fullscreencanvas,rect(0,0,screen.width,screen.height));
image1.picture.Bitmap:=fullscreen;
image1.width:=fullscreen.Width;
image1.height:=fullscreen.height;
image1.Picture.Bitmap.SaveToStream(smem);
smem.Position:=0;
socket.SendStream(smem);
end;
end;
end.
服务器端程序如下:
var
Form1: TForm1;
rmem:tmemorystream; //接收流
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
rmem:=tmemorystream.Create;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
rlen:integer; //接收的长度
bitmap:tbitmap; //接收的图片
buf:array[0..100000] of byte; //接收的长度
begin
rlen:=Socket.ReceiveLength;
Socket.ReceiveBuf(buf,rlen);
rmem.Write(buf,rlen);
rmem.Position:=0;
bitmap:=tbitmap.Create;
bitmap.LoadFromStream(rmem);
image1.Picture.Bitmap.Assign(bitmap);
//rmem.clear;如果我加上这句就会出错
end;
procedure TForm1.Button1Click(Sender: TObject);//按下就会抓屏
begin
ServerSocket1.Socket.Connections[0].SendText('getpic');
end;