图像处理出现 EoutofResources 问题,请问如何解决。 本人写了一个图像传输的东西,图像处理一段时间后出现 ...eoutofResources 存储空间不足,无法处理命令 有时是:..EoutofResources 请求资源在使用中。不清楚什么原因。源码如下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 unit IMThread;interfaceuses Classes, jpeg, Graphics, Types, SysUtils;type TImageChangeThread = class(TThread) private { Private declarations } bigBmp: TBitmap; smallBmp: TBitmap; ID: Integer; procedure updateMainForm; protected procedure Execute; override; public constructor create; destructor destroy; override; end;implementationuses Unit1;{ Important: Methods and properties of objects in VCL or CLX can only be used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure ImageChangeThread.UpdateCaption; begin Form1.Caption := 'Updated in a thread'; end; }{ ImageChangeThread }constructor TImageChangeThread.create;begin inherited create(true); Suspended := False; FreeOnTerminate := true; ID := 0;end;destructor TImageChangeThread.destroy;begin inherited destroy;end;procedure TImageChangeThread.updateMainForm;begin Inc(ID); Form1.Memo1.Lines.Add(IntToStr(ID)); Form1.Image2.Picture.Graphic := smallBmp;end;procedure TImageChangeThread.Execute;var TheChildRect: TRect; TheSubRect: TRect; Thejpg: TJPEGImage; TheStripHeight, i, inn, imm: Integer;begin TheStripHeight := 80; TheSubRect.Left := 0; TheSubRect.Top := 0; TheSubRect.Right := 80; TheSubRect.Bottom := TheStripHeight; bigBmp := TBitmap.create; bigBmp.LoadFromFile('1.bmp'); Thejpg := TJPEGImage.create; smallBmp := TBitmap.create; smallBmp.Width := 80; smallBmp.Height := TheStripHeight; Form1.Memo1.Lines.Clear; Form1.Memo1.Lines.Add('bigbmp.width=' + IntToStr(bigBmp.Width)); Form1.Memo1.Lines.Add('bigbmp.height=' + IntToStr(bigBmp.Height)); Form1.Image1.Picture.Graphic := bigBmp; for i := 1 to 1000 do begin inn := 0; repeat inn := inn + 1; imm := 0; repeat imm := imm + 1; TheChildRect.Left := (imm - 1) * 80; //拷贝目标块的x TheChildRect.Right := imm * 80; //拷贝目标块的底x坐标 TheChildRect.Top := (inn - 1) * TheStripHeight; //拷贝目标块的y TheChildRect.Bottom := inn * TheStripHeight; //拷贝目标块的底y坐标 smallBmp.Canvas.CopyRect(TheSubRect, bigBmp.Canvas, TheChildRect); Synchronize(updateMainForm); {Thejpg.Assign(smallBmp); Thejpg.CompressionQuality := 40; Thejpg.JPEGNeeded; Thejpg.Compress; } //Thejpg.SaveToFile('i:\small\' + IntToStr(i) + '_' + IntToStr(inn) + '_' + IntToStr(imm) + '.jpg'); Sleep(1); until (imm * 80) >= bigBmp.Width; until (inn * TheStripHeight) >= bigBmp.Height; end; bigBmp.Free; smallBmp.Free;end;end. 因为我想在主窗体上显示出图像处理结果 用到 Form1.Image2.Picture.Graphic := smallBmp;如果屏蔽掉这一行,就不会出现所描述的异常了。请问如何解决。谢谢! Form1.Image2.Picture.Graphic := smallBmp改成CopyRect的方式另外DC对象要先锁定再画Canvas.Lock;Canvas.CopyRect(目标尺寸,来源DC,来源尺寸);Canvas.Unlock; 首先 谢谢 SonicX(SonicX) ( ) 等了几天终于有人回答了。用了lock和unlock一段时间后仍然出现原来的问题。 输入问题?CASE RaveReport 打印出现问号 窗体问题! 很少见的错误,高手进来,非高手勿进,高分相赠。 求一工具 编程检测操作系统是Windows 2000是Server、Professional还是Advanced Server? 我这个想法可行吗? WM_Help消息能被什么钩子捕获? 请问哪位师兄有收发电子邮件的程序(含源码)? 我想制作一个小窗口,类似NetAnt,VamPire,可以浮在最上方,现在遇到困难: 图像处理问题(BMP->JPG 为啥老是提示EoutofResources),各位大侠帮忙...着急啊.. 有关ini文件的读写问题??????????????
Classes, jpeg, Graphics, Types, SysUtils;type
TImageChangeThread = class(TThread)
private
{ Private declarations }
bigBmp: TBitmap;
smallBmp: TBitmap;
ID: Integer;
procedure updateMainForm;
protected
procedure Execute; override;
public
constructor create;
destructor destroy; override;
end;implementation
uses Unit1;
{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure ImageChangeThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ ImageChangeThread }
constructor TImageChangeThread.create;
begin
inherited create(true);
Suspended := False;
FreeOnTerminate := true;
ID := 0;
end;
destructor TImageChangeThread.destroy;
begin
inherited destroy;
end;
procedure TImageChangeThread.updateMainForm;
begin
Inc(ID);
Form1.Memo1.Lines.Add(IntToStr(ID));
Form1.Image2.Picture.Graphic := smallBmp;
end;
procedure TImageChangeThread.Execute;
var TheChildRect: TRect;
TheSubRect: TRect;
Thejpg: TJPEGImage;
TheStripHeight, i, inn, imm: Integer;
begin
TheStripHeight := 80; TheSubRect.Left := 0;
TheSubRect.Top := 0;
TheSubRect.Right := 80;
TheSubRect.Bottom := TheStripHeight;
bigBmp := TBitmap.create;
bigBmp.LoadFromFile('1.bmp'); Thejpg := TJPEGImage.create; smallBmp := TBitmap.create;
smallBmp.Width := 80;
smallBmp.Height := TheStripHeight;
Form1.Memo1.Lines.Clear;
Form1.Memo1.Lines.Add('bigbmp.width=' + IntToStr(bigBmp.Width));
Form1.Memo1.Lines.Add('bigbmp.height=' + IntToStr(bigBmp.Height));
Form1.Image1.Picture.Graphic := bigBmp;
for i := 1 to 1000 do
begin
inn := 0;
repeat
inn := inn + 1;
imm := 0;
repeat
imm := imm + 1;
TheChildRect.Left := (imm - 1) * 80; //拷贝目标块的x
TheChildRect.Right := imm * 80; //拷贝目标块的底x坐标
TheChildRect.Top := (inn - 1) * TheStripHeight; //拷贝目标块的y
TheChildRect.Bottom := inn * TheStripHeight; //拷贝目标块的底y坐标
smallBmp.Canvas.CopyRect(TheSubRect,
bigBmp.Canvas, TheChildRect);
Synchronize(updateMainForm);
{Thejpg.Assign(smallBmp);
Thejpg.CompressionQuality := 40;
Thejpg.JPEGNeeded;
Thejpg.Compress; }
//Thejpg.SaveToFile('i:\small\' + IntToStr(i) + '_' + IntToStr(inn) + '_' + IntToStr(imm) + '.jpg');
Sleep(1);
until (imm * 80) >= bigBmp.Width;
until (inn * TheStripHeight) >= bigBmp.Height;
end;
bigBmp.Free;
smallBmp.Free;
end;end.
如果屏蔽掉这一行,就不会出现所描述的异常了。请问如何解决。谢谢!
另外DC对象要先锁定再画
Canvas.Lock;
Canvas.CopyRect(目标尺寸,来源DC,来源尺寸);
Canvas.Unlock;