To:de410这是客户端的程序,故此应是客户端的空间。To:liuls这只是客户端的程序,服务器端主要是将屏幕图像转化为ZipData: WideString传送过来,此过程是将ZipData还原为图像数据。To:znxia,Length(ZipData)可正确得出Integer数值,估计没有问题。谢谢大家的回复!附上完整同一Form截屏显示代码,能正确执行。(代码来源网上)//----------------------------------function TForm1.GetScreen:WideString; //相当于服务器程序Var SourceDC,DestDC:HDC; Bhandle:HBITMAP; BitMap:TBitMap; BmpStream,Deststream:TMemoryStream; SourceStream:TCompressionStream; Count:Integer; toZipData: WideString;Begin SourceDC:=CreateDC('display','','',nil); {得到屏幕的 DC} DestDC:=CreateCompatibleDC(SourceDC); {建立临时 DC} Bhandle:=CreateCompatibleBitmap(SourceDC,Screen.Width, Screen.Height); {建立位图} SelectObject(DestDC,Bhandle); {选择位图DC} BitBlt(DestDC,0,0,Screen.Width, Screen.Height,SourceDC,0,0,SRCCOPY); {拷贝整个屏幕} BitMap:=TBitMap.Create; BitMap.Handle := Bhandle; {保存屏幕位图到 BitMap中} BmpStream:=TMemoryStream.Create; BitMap.SaveToStream(BmpStream); {建立位图数据的内存流} count:=BmpStream.Size; {保存位图的大小} DestStream:=TMemoryStream.Create; {目标流,保存压缩数据} SourceStream:=TCompressionStream.Create(clMax, DestStream); {构建压缩流,采用最大化压缩,并保存到目标流中} try BmpStream.SaveToStream(SourceStream); {压缩位图流} SourceStream.Free; {完成压缩,释放压缩流} BmpStream.Clear; {清空原来位图流} BmpStream.WriteBuffer(Count, Sizeof(Count)); {将原来位图的大小保存到新的位图流中,以便使用} BmpStream.CopyFrom(DestStream, 0); {将压缩数据附加到新的位图流后面} BmpStream.Position := 0; finally try SetLength(toZipData,BmpStream.Size); BmpStream.Position:=0; BmpStream.Read(toZipData[1],BmpStream.Size); //这样把Stream里的内容放进String finally Result:=toZipData; end; DestStream.Free; BmpStream.Destroy ; BitMap.Destroy; DeleteDC(SourceDC); ReleaseDC(Bhandle,SourceDC); end; {释放有关资源}End; procedure TForm1.displayScreen(ZipData: WideString); //相当于客户端程序Var StreamStr,DestStream:TMemoryStream; SourceStream:TDecompressionStream; count:Integer; buffer
ointer;begin StreamStr := TMemoryStream.Create; ScreenImage.Picture.Bitmap:=nil; StreamStr.Position:=0; //先确定要从哪里开始放String StreamStr.Write(ZipData[1],Length(ZipData)); //这样把String的内容放进Stream StreamStr.Position := 0; StreamStr.ReadBuffer(Count, Sizeof(Count)); {得到位图的大小} GetMem(Buffer,Count); {申请数据空间} DestStream := TMemoryStream.Create; SourceStream := TDecompressionStream.Create(StreamStr); {构建解压流,压缩数据由StreamStr 流得到} Try SourceStream.ReadBuffer(Buffer^,Count); {读出解压数据} DestStream.WriteBuffer(Buffer^,Count); {保存到位图流中} DestStream.Position := 0; ScreenImage.Picture.Bitmap.LoadFromStream(DestStream); {显示到屏幕上} Finally FreeMem(Buffer); DestStream.Destroy; SourceStream.Destroy; End; StreamStr.Free ;end;procedure TForm1.BitBtn1Click(Sender: TObject);begin displayScreen(GetScreen); //执行截屏并显示end;//----------------------------------