我使用idudpclient和服务器进行了图像流传输并且一切运行良好,但对于发送的每个图像,我从任务管理器看到内存使用率较高,一分钟后我出现此错误“没有足够的存储空间可供处理这个命令“。我试图释放在运行时创建的所有流,但没有成功。这是一个示例代码:
procedure TForm5.mandaimg;
var
bmp,bmp1,bmp2,bmp3,bmp4: TBitmap;
jpg1,jpg2,jpg3,jpg4: TJPEGImage;
Strm1,Strm2,Strm3,Strm4 : TMemoryStream;
cStrm1,cStrm2,cStrm3,cStrm4 : TMemoryStream; //stream compressi
strmByte1,strmByte2,strmByte3,strmByte4:TIdBytes;
begin
strmByte1:=nil;
strmByte2:=nil;
strmByte3:=nil;
strmByte4:=nil;
if(IdUDPClient1.Connected = false)then
begin
IdUDPClient1.connect;
IdUDPClient2.connect;
IdUDPClient3.connect;
IdUDPClient4.connect;
end;
if(IdUDPClient1.Connected)then
begin
Strm1 := TMemoryStream.Create;
Strm1.Position := 0;
Strm2 := TMemoryStream.Create;
Strm2.Position := 0;
Strm3 := TMemoryStream.Create;
Strm3.Position := 0;
Strm4 := TMemoryStream.Create;
Strm4.Position := 0;
cStrm1 := TMemoryStream.Create;
cStrm1.Position := 0;
cStrm2 := TMemoryStream.Create;
cStrm2.Position := 0;
cStrm3 := TMemoryStream.Create;
cStrm3.Position := 0;
cStrm4 := TMemoryStream.Create;
cStrm4.Position := 0;
try
jpg1 := TJPEGImage.Create;
jpg2 := TJPEGImage.Create;
jpg3 := TJPEGImage.Create;
jpg4 := TJPEGImage.Create;
bmp1 := TBitmap.Create;
bmp2 := TBitmap.Create;
bmp3 := TBitmap.Create;
bmp4 := TBitmap.Create;
try
bmp := TBitmap.Create;
try
screenshot(bmp);
img1.Picture.Assign(bmp);
CropBitmap(img1.Picture.Bitmap, Bmp1, 0,0, Round(Screen.width/2), Round(Screen.Height/2));
// Image1.Picture.Bitmap:=Bmp1;
CropBitmap(img1.Picture.Bitmap, Bmp2, Round(Screen.width/2),0, Round(Screen.width/2), Round(Screen.Height/2));
// Image2.Picture.Bitmap:=Bmp2;
CropBitmap(img1.Picture.Bitmap, Bmp3, 0,Round(Screen.Height/2), Round(screen.width/2), Round(Screen.Height/2));
// Image3.Picture.Bitmap:=Bmp3;
CropBitmap(img1.Picture.Bitmap, Bmp4, Round(Screen.width/2),Round(Screen.Height/2), Round(Screen.width/2), Round(Screen.Height/2));
// Image4.Picture.Bitmap:=Bmp4;
jpg1.Assign(bmp1);
jpg1.CompressionQuality:=TrackBar1.Position;
jpg1.Compress;
jpg2.Assign(bmp2);
jpg2.CompressionQuality:=TrackBar1.Position;
jpg2.Compress;
jpg3.Assign(bmp3);
jpg3.CompressionQuality:=TrackBar1.Position;
jpg3.Compress;
jpg4.Assign(bmp4);
jpg4.CompressionQuality:=TrackBar1.Position;
jpg4.Compress;
finally
jpg1.SaveToStream(Strm1);
jpg2.SaveToStream(Strm2);
jpg3.SaveToStream(Strm3);
jpg4.SaveToStream(Strm4);
Strm1.Position:=0;
Strm2.Position:=0;
Strm3.Position:=0;
Strm4.Position:=0;
CompressStream(Strm1,cStrm1);
CompressStream(Strm2,cStrm2);
CompressStream(Strm3,cStrm3);
CompressStream(Strm4,cStrm4);
end;
finally
jpg1.Free;
jpg2.Free;
jpg3.Free;
jpg4.Free;
bmp1.Free;
bmp2.Free;
bmp3.Free;
bmp4.Free;
end;
cStrm1.Position := 0;
cStrm2.Position := 0;
cStrm3.Position := 0;
cStrm4.Position := 0;
try
ReadTIdBytesFromStream(cStrm1,strmByte1,cStrm1.Size);
IdUDPClient1.SendBuffer('192.168.17.132',1235,strmByte1);
ReadTIdBytesFromStream(cStrm2,strmByte2,cStrm2.Size);
IdUDPClient2.SendBuffer('192.168.17.132',1236,strmByte2);
ReadTIdBytesFromStream(cStrm3,strmByte3,cStrm3.Size);
IdUDPClient3.SendBuffer('192.168.17.132',1237,strmByte3);
ReadTIdBytesFromStream(cStrm4,strmByte4,cStrm4.Size);
IdUDPClient4.SendBuffer('192.168.17.132',1238,strmByte4);
except
TrackBar1.Position:=TrackBar1.Position-1;
end;
finally
FreeAndNil(strm1);
FreeAndNil(strm2);
FreeAndNil(strm3);
FreeAndNil(strm4);
FreeAndNil(cstrm1);
FreeAndNil(cstrm2);
FreeAndNil(cstrm3);
FreeAndNil(cstrm4);
strmByte1:=nil;
strmByte2:=nil;
strmByte3:=nil;
strmByte4:=nil;
end;
end;
end;
我能做点什么吗?
提前致谢。
(我正在使用delphi xe5)