遠端控制篇:抓取遠端螢幕影像 (轉)

worldblog發表於2007-12-04
遠端控制篇:抓取遠端螢幕影像 (轉)[@more@]

控制篇:抓取遠端螢幕影像

{抓螢幕影像,儲存為流--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 .pas
{先定義變數count,DestStream,Stream}
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.Reauffer(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);

--------------------------------------------
湖北襄樊  官本和(to:gbh12345@china.com">gbh12345@china.com)  2001.4
詳見主頁源:
21cn.yeah">


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-988324/,如需轉載,請註明出處,否則將追究法律責任。

相關文章