O
onyliu
Unregistered / Unconfirmed
GUEST, unregistred user!
TIdUDPClient 端
//***************************************************
procedure TUDPMainForm.btn1Click(Sender: TObject);
var
buffer : array [0..10000] of Byte;
j: TJPEGImage;
tstream : Tmemorystream;
i ,sendsize,ci,yu : Integer;
begin
j:= TJPEGImage.Create;
j.LoadFromFile('D:/a.jpg');
tstream := Tmemorystream.Create;
//j.CompressionQuality := 50;
//j.JPEGNeeded;
//j.Compress;
j.SaveToStream(tstream);
tstream.Position := 0;
sendsize := tstream.Size;
// 这里有个小问题: 上面注释的三行 如果不注释 sendsize只能取到0 注释后就正常了 ?/? 为什么啊 ????
ci := sendsize div 8092;
yu := sendsize mod 8092;
for i:= 1 to ci do
begin
tstream.WriteBuffer(buffer,8092);
UDPClient.SendBuffer(buffer,8092);
end;
if yu >0 then
begin
tstream.ReadBuffer(buffer,yu);
UDPClient.SendBuffer(buffer,yu);
end;
j.Free;
end;
***************************************************//
TIdUDPServer 端
procedure TUDPMainForm.UDPServerUDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle);
var
sendsize : Integer;
begin
sendsize := AData.Size;
{t:= TJPEGImage.Create;
t.LoadFromStream(AData);
image1.Picture.Bitmap.Assign(t);
t.Free;}//在网上搜的一个例子就是这样的 行不通---我想问题是分包发送的
//但是为什么 t.LoadFromStream(AData); 这句就报错呢(我的理解:包不完整顶多图片显示有问题啊)
// 下面分包处理
if sendsize= 8092 then
begin
DataStream.CopyFrom(AData,AData.Size);
//DataStream 定义为 Tstream 运行这程序就死了
//如果定义成 Tmemorystream 则
///DataStream.WriteBuffer(buffer,8092); tstream.ReadBuffer(buffer,8092);
//程序报错
end
else
begin
DataStream.CopyFrom(AData,AData.Size);
try
DataStream.Position := 0;
t.LoadFromStream(DataStream);
image1.Picture.Bitmap.Assign(t);
finally
t.Free;
end;
end;
end;
************************************************//////////////////
哪位弄的,帮我看看啊。。谢谢啊!
//***************************************************
procedure TUDPMainForm.btn1Click(Sender: TObject);
var
buffer : array [0..10000] of Byte;
j: TJPEGImage;
tstream : Tmemorystream;
i ,sendsize,ci,yu : Integer;
begin
j:= TJPEGImage.Create;
j.LoadFromFile('D:/a.jpg');
tstream := Tmemorystream.Create;
//j.CompressionQuality := 50;
//j.JPEGNeeded;
//j.Compress;
j.SaveToStream(tstream);
tstream.Position := 0;
sendsize := tstream.Size;
// 这里有个小问题: 上面注释的三行 如果不注释 sendsize只能取到0 注释后就正常了 ?/? 为什么啊 ????
ci := sendsize div 8092;
yu := sendsize mod 8092;
for i:= 1 to ci do
begin
tstream.WriteBuffer(buffer,8092);
UDPClient.SendBuffer(buffer,8092);
end;
if yu >0 then
begin
tstream.ReadBuffer(buffer,yu);
UDPClient.SendBuffer(buffer,yu);
end;
j.Free;
end;
***************************************************//
TIdUDPServer 端
procedure TUDPMainForm.UDPServerUDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle);
var
sendsize : Integer;
begin
sendsize := AData.Size;
{t:= TJPEGImage.Create;
t.LoadFromStream(AData);
image1.Picture.Bitmap.Assign(t);
t.Free;}//在网上搜的一个例子就是这样的 行不通---我想问题是分包发送的
//但是为什么 t.LoadFromStream(AData); 这句就报错呢(我的理解:包不完整顶多图片显示有问题啊)
// 下面分包处理
if sendsize= 8092 then
begin
DataStream.CopyFrom(AData,AData.Size);
//DataStream 定义为 Tstream 运行这程序就死了
//如果定义成 Tmemorystream 则
///DataStream.WriteBuffer(buffer,8092); tstream.ReadBuffer(buffer,8092);
//程序报错
end
else
begin
DataStream.CopyFrom(AData,AData.Size);
try
DataStream.Position := 0;
t.LoadFromStream(DataStream);
image1.Picture.Bitmap.Assign(t);
finally
t.Free;
end;
end;
end;
************************************************//////////////////
哪位弄的,帮我看看啊。。谢谢啊!