请大侠出手帮忙! Stream read error 出错!(100)

  • 主题发起人 主题发起人 d99
  • 开始时间 开始时间
D

d99

Unregistered / Unconfirmed
GUEST, unregistred user!
同一Form执行截屏和显示能正常,换成服务器/客户端模式就出现“Stream read error”报错!经跟踪调试,屏幕压缩数据经WideString转换能正确传递,Buffer值在同一Form下是$DA0004,服务器/客户端模式下是$7220004。代码如下:----------------------------------procedure TfrmGetScreen.displayScreen(ZipData: WideString);Var StreamStr,DestStream:TMemoryStream; SourceStream:TDecompressionStream; count:Integer; Buffer:pointer;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); //读出解压数据//××执行到这里直接跳到 Finally DestStream.WriteBuffer(Buffer^,Count); //保存到位图流中// DestStream.Position := 0; ScreenImage.Picture.Bitmap.LoadFromStream(DestStream); //显示到屏幕上// Finally FreeMem(Buffer); DestStream.Destroy; SourceStream.Destroy; End; StreamStr.Free ;end;
 
可能是GetMem(Buffer,Count); //申请数据空间申请的数据空间是服务器端的空间还是客户端的空间,这个地方出的问题~~
 
实现 服务器/客户端模式 就只一个过程?
 
ZipData是WideString类型的,Length(ZipData));就有可能有问题,例如ZipData:='INT类型';Length(ZipData) = 5而不是7,但实际上你需要7.
 
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:pointer;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;//----------------------------------
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
495
import
I
I
回复
0
查看
640
import
I
I
回复
0
查看
1K
import
I
I
回复
0
查看
948
import
I
后退
顶部