我正在使用带有 indy10 组件的 delphi xe4,我想将图像从 Tidudpclient 发送到 Tidudpserver。我已经使用 tcp 组件完成了此操作,但相同的代码不适用于 udp。我怎么能这样做?提前致谢!
Timage(客户端)--->streamUDP-->Timage(服务器)
客户端----------------------------------------------------------- 发送图片
var
pic: tbitmap;
Strm : TMemoryStream;
img2:Timage;
buffer:TIdBytes;
begin
try
img2:=Timage.Create(nil);
pic:=Tbitmap.Create;
Takekpic(pic);
BMPtoJPG(pic,img2);
Strm := TMemoryStream.Create;
img2.Picture.bitmap.SaveToStream(strm);
Strm.Position:=0;
ReadTIdBytesFromStream(Strm,buffer,SizeOf(Strm),0);
IdTrivialFTPServer1.SendBuffer('192.168.17.128',1234,buffer);
finally
strm.Free;
end;
end;
服务器端 - - - - - - - - - - - - - - - - - - - - - - - - ---- 阅读图片
procedure TForm6.IdTrivialFTP1UDPRead(AThread: TIdUDPListenerThread;
const AData: TIdBytes; ABinding: TIdSocketHandle);
var
Strm : TMemoryStream;
Jpg: TJpegImage;
begin
Strm := TMemoryStream.Create;
try
WriteTIdBytesToStream(Strm,AData,SizeOf(AData),0);
strm.Position:=0;
Jpg := TJpegImage.Create;
jpg.LoadFromStream(Strm); <---- error while reading (JPEG Error #53)
img1.Picture.assign(jpg);
finally
strm.Free;
Jpg.Free;
end;
end;
这段代码有什么问题?