关于TidTCPServer向TidTCPClient发送图象的问题(50分)

  • 主题发起人 主题发起人 netcore
  • 开始时间 开始时间
N

netcore

Unregistered / Unconfirmed
GUEST, unregistred user!
client端:
procedure TForm1.Button1Click(Sender: TObject);
var
t:TMemoryStream;
begin
try
itc1.Host:=edit1.Text;
itc1.Port:=88;
try
t:=TMemoryStream.Create;
itc1.Connect;
itc1.WriteLn('OK ');
itc1.ReadStream(t,-1,true); ////////////////
t.SaveToFile('c:/test.bmp');
image1.Picture.Graphic.LoadFromStream(t);
finally
t.Free ;
end;
except
application.MessageBox('获取数据失败','注意',MB_OK);
end;
itc1.Disconnect;
end;

Server端:
procedure TForm1.its1Execute(AThread: TIdPeerThread);
var
v1,c,s:string;
r1:olevariant;
st1:Tmemorystream;
begin
try
v1:=Athread.Connection.ReadLn;
c:=copy(v1,1,2);
if uppercase(c)='OK' then
begin
try
st1:=Tmemorystream.Create;
image1.picture.bitmap.SaveToStream(st1);
Athread.Connection.WriteStream(st1);
finally
st1.Free;
end;
end;
except
end;
end;

流程:
1、client端点击button1向server端发送一个准备就绪的消息‘OK’
2、server端接收到后向client端返回一幅图片

问题:
client端点击button1后在itc1.ReadStream(t,-1,true)语句处死掉了;

请问问题所在?相关例子只找到从client端发送到server端的。

 
应该是服务端接把图片读完以后没有把指针指回来开头吧。image1.picture.bitmap.SaveToStream(st1);
st1.seek(soFromBeginning,0); //试试加上这句
Athread.Connection.WriteStream(st1);
 
加上这句之后问题依旧
 
不知道是这个问题是不是太简单了没人愿意回答

注明:该图像是大小为58*58
 
继续求解…………………………

提示:
把client端的itc1.ReadStream(t,-1,true);
改为itc1.ReadStream(t)后
运行提示错误:'Out of memory while expanding memory stream'

 
问题解决,虽然talent002的答案没有解决我所问的问题,但是避免了另问题,所以散分
 
接受答案了.
 
后退
顶部