On Tue, 27 Dec 2005 17:30:32 +0200
Markku Niskanen <[EMAIL PROTECTED]> wrote:

> I am still fighting my way through the graphics jungle. So far the only
> problem has been the consumption of GDI handles which happens in 
> this code fragment which is part of mouseMove rectangle/ellipse 
> drawing routine where during a mouse move I first
> 
> 1) Save the original image  (editImage bitmap)
> 2) draw the ellipse to editImage
> 3) Project the image to magnified area (grid)
> 4) Restore the saved image to editImage
> 
> Only after keyup I finally update the editImage bitmap 
> 
> I have narrowed down the leak to these two functions; if I exit
> from them immediately the memory leak disappears... Other than
> this problem the icon editor is already usable, it reads xpm and
> ico files and writes them as well. And it is beautiful :)
> ...
> editImage       : TLazIntfImage;
> ...
> var  originalImage : TlazIntFImage; // this is where I save it
>       originalBitmap: TBitmap;
>       BmpHnd,MaskHnd: HBitmap;
> 
>   procedure saveBitmap();
>   begin
>     // create the original image and load a bitmap to it
>     originalImage := originalBitmap.CreateIntfImage;
>     originalImage.LoadFromBitmap(BmpHnd,MaskHnd);
>   end;
> 
>   procedure restoreBitmap();
>    var     BmpHnd,MaskHnd: HBitmap;
>   begin
>    // load editImage from the original bitmap
>     originalImage.CreateBitmap(BmpHnd,MaskHnd,false);
>     editImage.LoadFromBitmap(BmpHnd,MaskHnd);
>     originalImage.Free; // should'nt this free the resources?
>                                // or should I also free something else?

The TLazIntfImage creates new bitmap handle objects everytime you call
CreateBitmap.

To copy from one TLazIntfImage to another you can do that directly
editImage.Assign(originalImage);

If you need speed, you can copy the content of PixelData, MaskData directly.


>   end;
> 
> ...
>   case Tool of
>   Ellipse:
>             begin
>              saveBitmap; // save the original
>          // irrelevant from here.... just drawing the stuff to tmpBitmap
>              tmpBitMap.Canvas.Brush.Style := bsSolid;
>              tmpBitMap.Canvas.Pen.Color   := FPColorToTcolor(currentFG);
>              tmpBitMap.Canvas.Brush.Color := FPColorToTcolor(currentBG);
> 
> tmpBitmap.Canvas.Ellipse(rectStartX,rectStarty,RectEndX,rectEndY);
>              editImage.loadFromBitmap(BmpHnd,MaskHnd);
>              drawGrid; // draw the editor grid + image
>          // ...up to this point
>              restoreBitmap; //restore the original 
>             end;


Mattias

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to