当前位置:首页 > 软件开发 > net
firefox

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

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

{抓屏幕图像,保存为内存流--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);

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

 ↓相关文章:
© 2006-2008 All Rights Reserved