ITPub博客

首页 > IT基础架构 > 网络安全 > 远程控制篇:抓取远程屏幕图像 (转)

远程控制篇:抓取远程屏幕图像 (转)

原创 网络安全 作者:worldblog 时间:2007-12-04 13:09:35 0 删除 编辑
远程控制篇:抓取远程屏幕图像 (转)[@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 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);

--------------------------------------------
湖北襄樊  官本和(Mailto:gbh12345@china.com">gbh12345@china.com)  2001.4
详见主页源程序
Delphi21cn.yeah.NET">http://delphi21cn.yeah.net
http://personal.hb.cninfo.net/~gbh


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-988324/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    6241
  • 访问量
    2405155