分块和比较都很容易,如想速度快,这样是不理想的,因为当宽屏变化大的时候,压缩和传输都会很慢,在INTERNET更明显,比较图像可以用内存指针,得到两幅图的SCANLINE指针,时行比较内存即可得出一样否
procedure TScreenThread.MakeScreenData; //初始化操作
Function MultiRoot(ANumber, MaxRoot: Cardinal): Cardinal;
Begin
If MaxRoot>0 then
While (ANumber mod MaxRoot)<>0 do
MaxRoot:= MaxRoot-1;
Result:= MaxRoot;
End;
Var
i: Integer;
begin
If Isworking then
ReleaseScreenData;
Isworking:=True;
i:=Trunc(sqrt(FMaxBlockcount)); //开始计算block, X,Y方向最大块数;
BlockRowCount:=MultiRoot(Screen.Height,i); //高度分块
BlockHeight:=Screen.Height div BlockRowCount;
BlockColumnCount:=MultiRoot(Screen.Width,Trunc(FMaxBlockcount/BlockRowCount));
BlockWidth:=Screen.Width div BlockColumnCount;
BlockCount:=BlockColumnCount * BlockRowCount;
BlockBound:=Rect(0, 0, BlockWidth, BlockHeight);
SetLength(ScreenBitmaps, BlockCount); //开始创建screenbitmaps数组中所有元素
For i:=0 to BlockCount-1 do
Begin
ScreenBitmaps.Bound:=Rect(0,0,BlockWidth,BlockHeight);
OffsetRect(ScreenBitmaps.Bound, (i mod BlockColumnCount) * BlockWidth, (i div BlockColumnCount) * BlockHeight);
ScreenBitmaps.newbmp:=tmemorystream.Create;
ScreenBitmaps.LastScreen:=tmemorystream.Create;
End;
ScreenCanvas:=TCanvas.Create; //创建screencanvas画布
ScreenCanvas.Handle:= GetDC(0);
TempStream:=Tmemorystream.Create; //创建比较图片所用内存流
mytemp:=tmemorystream.Create; //创建发送数据所用内存流
BMP:=TBitmap.Create; //创建抓屏所用bmp
bmp.Width:=blockwidth;
bmp.Height:=blockheight;
fPixelFormat:=pf8bit; //设定默认色彩位数
try
i:=-1;
DataCom.Socket.Write(i);
DataCom.Socket.Write(screen.Width); //屏幕宽度
DataCom.Socket.Write(screen.Height); //屏幕高度
DataCom.Socket.Write(FMaxBlockcount); //分块长度
except
end;
end;
屏幕分块代码