本人写了一个图像传输的东西,图像处理一段时间后出现 ...eoutofResources 存储空间不足,无法处理命令  有时是:..EoutofResources 请求资源在使用中。不清楚什么原因。源码如下。

解决方案 »

  1.   

    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;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.
      

  2.   

    因为我想在主窗体上显示出图像处理结果 用到 Form1.Image2.Picture.Graphic := smallBmp;
    如果屏蔽掉这一行,就不会出现所描述的异常了。请问如何解决。谢谢!
      

  3.   

    Form1.Image2.Picture.Graphic := smallBmp改成CopyRect的方式
    另外DC对象要先锁定再画
    Canvas.Lock;
    Canvas.CopyRect(目标尺寸,来源DC,来源尺寸);
    Canvas.Unlock;
      

  4.   

    首先 谢谢 SonicX(SonicX) ( )  等了几天终于有人回答了。用了lock和unlock一段时间后仍然出现原来的问题。