一个用indy tcp传送图象的例子
procedure TForm1.BitBtn1Click(Sender: TObject);
var
Temp:TMemoryStream;
begin
Temp:=TMemoryStream.Create;
//将图像文件保存到内存流
Image1.Picture.Graphic.SaveToStream(Temp);
//发送图像信息
IdTCPClient1.Connect();
IdTCPClient1.writestream(Temp);
// edit1.Text:=IdTCPClient1.ReadString(10);
IdTCPClient1.Disconnect();
Temp.Free ;
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
const
TempImageFile='c:/test.bmp';
//设置的临时图像文件
var
t:TMemoryStream;
begin
t:=TMemoryStream.Create;
AThread.Connection.ReadStream(t,-1,True);
//AThread.Connection.Write('test');
//从连接中取得流式数据
t.SaveToFile(TempImageFile);
Image2.Picture.LoadFromFile(TempImageFile);
t.Free ;
end;
end.