程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 遠程控制篇:抓取遠程屏幕圖像

遠程控制篇:抓取遠程屏幕圖像

編輯:Delphi

遠程控制篇:抓取遠程屏幕圖像

{抓屏幕圖像,保存為內存流--BMP流,壓縮BMP流,JPG流,以及使用流}
{在網絡中傳送BMP流和JPG流的速度沒測試過}
{BMP流的壓縮是無損壓縮}
{
全局變量
memoryStream:TMemoryStream;
memoryStream:=TMemoryStream.create;
}

var
image:Timage;
jpgstream:TJPEGImage;
ss:tcanvas;

begin
ss:=tcanvas.Create;
ss.Handle:=getdc(0);
image:=timage.Create(self);
image.width:=Screen.width;
image.Height:=screen.Height ;
image.picture.bitmap.PixelFormat:= pf16bit;
bitblt(image.canvas.handle,0,0,image.width,image.height,ss.handle,0,0,srccopy);

{大大的原始BMP流
image.picture.bitmap.SaveToStream(memoryStream);
}

{無損壓縮BMP流  uses Zlib.pas
{先定義變量count,DestStream,SourceStream}
image.picture.bitmap.SaveToStream(memoryStream);
Count:=memoryStream.Size;
DestStream:=TMemoryStream.Create;
{壓縮方式:clnone,clfastest,cldefault,clmax}
SourceStream:=TComPRessionStream.Create(cldefault, DestStream);
try
memoryStream.SaveToStream(SourceStream);
SourceStream.Free;
memoryStream.Clear;
memoryStream.WriteBuffer(Count, SizeOf(Count));
memoryStream.CopyFrom(DestStream, 0);
finally
DestStream.Free;
end;
}

{JPG流  uses jpeg
jpgstream:= TJPEGImage.Create;
jpgstream.Assign(image.picture.bitmap);
jpgstream.CompressionQuality:=50; {壓縮質量}
jpgstream.Compress;
jpgstream.SaveToStream(memoryStream);{保存為JPG流}
jpgstream.free;
}

ReleaseDC(0,ss.Handle);
image.free;

{發送內存流...}

-----------------------------------------------------
{接收內存流...}

{使用BMP流
image.Picture.Bitmap.LoadFromStream(bmpStream);}

{還原壓縮的BMP流  uses:Zlib.pas
先定義變量count,buffer,DestStream,SourceStream
memoryStream是壓縮的BMP流
memoryStream.ReadBuffer(Count, SizeOf(Count));
GetMem(Buffer, Count);
DestStream:=TMemoryStream.Create;
SourceStream:=TDecompressionStream.Create(memoryStream);
Try
SourceStream.ReadBuffer(Buffer^, Count);
  DestStream.WriteBuffer(Buffer^, Count);
  DestStream.Position:=0;
  image.Picture.Bitmap.LoadFromStream(DestStream);
finally
FreeMem(Buffer);
DestStream.Free;
end;
}

使用JPG流 image.Picture.Assign(jpgstream);

--------------------------------------------
湖北襄樊  官本和([email protected])  2001.4
詳見主頁源程序:
http://Delphi21cn.yeah.Net
http://personal.hb.cninfo.Net/~gbh

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved