我的程序中用到的代码,你看看是否有用:
var
s,s1,m:string;
desk:tcanvas;
bitmap:tbitmap;
jpg:tjpegimage;
hdesk:thandle;
begin
s:=socket.ReceiveText;
if s='gets' then //file://服务器端发出申请
begin
try
m1:=tmemorystream.Create; //file://初始化流m1,在用sendstream(m1)发送流后,
//file://它将保留到socket对话结束,
//file://不能用手工free掉,否则会触发异常
bitmap:=tbitmap.Create;
jpg:=tjpegimage.Create;
desk:=tcanvas.Create; //file://以下代码为取得当前屏幕图象
desk.Handle:=getdc(hwnd_desktop);
with bitmap do
begin
width:=screen.Width;
height:=screen.Height;
canvas.CopyRect(canvas.cliprect,desk,desk.cliprect);
end;
jpg.Assign(bitmap); //file://将图象转成JPG格式
jpg.CompressionQuality:=30;
//m1.clear;
jpg.SaveToStream(m1); //file://将JPG图象写入流中
jpg.free;
m1.Position:=0;
s1:=inttostr(m1.size);
Socket.sendtext(s1); //file://发送图象大小
finally
bitmap.free;
desk.free;
end;
end;