S
sxdthonda
Unregistered / Unconfirmed
GUEST, unregistred user!
大家好,我现在使用Indy9的IdUdpClient和IdUdpServer控件。思路是先设置IdUdpClient和IdUdpServer的IP及端口,然后调置Active为True,当用户点Button1时,抓屏,然后用Idudpclient发送,Idudpserver获取数据。
程序代码段:
procedure TForm1.FormCreate(Sender: TObject);
begin
picstream:=tmemorystream.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
picstream.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
jpic:tjpegimage;
bpic:tbitmap;
s:string;
begin
jpic:=tjpegimage.Create;
bpic:=tbitmap.Create;
bpic.Width :=100;//screen.width;
bpic.Height :=100;//screen.Height ;
bitblt(bpic.Canvas.Handle ,0,0,bpic.Width ,bpic.Height ,getdc(0),0,0,srccopy);
jpic.Assign(bpic);
jpic.CompressionQuality :=10;
jpic.Compress;
jpic.SaveToStream(picstream);
// compressStream( picstream);
picstream.Position :=0;
//jpic.SaveToFile('d:1.jpg');
bpic.Free;
jpic.Free;
showmessage(inttostr(picstream.Size));
form1.IdUDPClient1.sendbuffer(picstream,picstream.size);
picstream.SaveToFile('d:/picstream.jpg');
picstream.Clear;
end;
procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
jpic:tjpegimage;
getstream:tmemorystream;
begin
adata.Seek(0,0);
getstream:=tmemorystream.Create;
getstream.Position:=0;
getstream.LoadFromStream(adata);
getstream.SaveToFile('d:/dest.jpg');
jpic:=tjpegimage.Create;
getstream.Position :=0;
jpic.LoadFromStream(getstream); --运行这句时就出错。
image1.Picture.Bitmap.Assign(jpic);
jpic.Free;
getstream.Free;
end;
而且检查生成的二个Jpg文件,发现'd:/picstream.jpg'可打开,而'd:/dest.jpg'无法打开,但二个文件的大小一样。请大家指点一下。多谢了。
程序代码段:
procedure TForm1.FormCreate(Sender: TObject);
begin
picstream:=tmemorystream.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
picstream.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
jpic:tjpegimage;
bpic:tbitmap;
s:string;
begin
jpic:=tjpegimage.Create;
bpic:=tbitmap.Create;
bpic.Width :=100;//screen.width;
bpic.Height :=100;//screen.Height ;
bitblt(bpic.Canvas.Handle ,0,0,bpic.Width ,bpic.Height ,getdc(0),0,0,srccopy);
jpic.Assign(bpic);
jpic.CompressionQuality :=10;
jpic.Compress;
jpic.SaveToStream(picstream);
// compressStream( picstream);
picstream.Position :=0;
//jpic.SaveToFile('d:1.jpg');
bpic.Free;
jpic.Free;
showmessage(inttostr(picstream.Size));
form1.IdUDPClient1.sendbuffer(picstream,picstream.size);
picstream.SaveToFile('d:/picstream.jpg');
picstream.Clear;
end;
procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
jpic:tjpegimage;
getstream:tmemorystream;
begin
adata.Seek(0,0);
getstream:=tmemorystream.Create;
getstream.Position:=0;
getstream.LoadFromStream(adata);
getstream.SaveToFile('d:/dest.jpg');
jpic:=tjpegimage.Create;
getstream.Position :=0;
jpic.LoadFromStream(getstream); --运行这句时就出错。
image1.Picture.Bitmap.Assign(jpic);
jpic.Free;
getstream.Free;
end;
而且检查生成的二个Jpg文件,发现'd:/picstream.jpg'可打开,而'd:/dest.jpg'无法打开,但二个文件的大小一样。请大家指点一下。多谢了。