TImage problems lazarus / 39-Graphics ---------------------------------------------------------------------- radioman · 2011-09-14 19:20 I'm trying to port a Delphi application to Lazarus (using Lazarus 0.9.30 and FPC 2.4.2) and I'm having problems with TImage. The program uses a TImage to display a map, and over this image, another TImage with transparent property enabled. On this second TImage the program draw some locations and tracks. The first problem is the transparent function does not work at all. The second image starts transparent but as soon as I draw something on it, it becomes not transparent (of course the lower left pixel is untouched). So I tried a slower workaround: I made the TImage with the map not visible and everytime I need to mark something on the map, I copy the canvas from the first image to the second one, and then I draw on the second image. The problem now is the TImage.Canvas.CopyRect procedure does not copy the content of image. It copy the content of the area where the image is. So instead a map, I get a perfect copy of buttons, comboboxes, etc... exactly the portion of the form where the image is placed (but not visible). Am I missing something? Any ideas? Thanks in advance! ---------------------------------------------------------------------- lainz · 2011-09-14 21:03 Quote from: radioman on September 14, 2011, 09:20:53 pmThe first problem is the transparent function does not work at all. The second image starts transparent but as soon as I draw something on it, it becomes not transparent (of course the lower left pixel is untouched). You must use color transparency because alpha is not available by default. Quote from: radioman on September 14, 2011, 09:20:53 pmThe problem now is the TImage.Canvas.CopyRect procedure does not copy the content of image. It copy the content of the area where the image is. So instead a map, I get a perfect copy of buttons, comboboxes, etc... exactly the portion of the form where the image is placed (but not visible). Use Image.Picture (Image.Picture.Bitmap.Canvas) instead Image.Canvas. Edit: here is the best explanation http://wiki.lazarus.freepascal.org/Developing_with_Graphics#Draw_to_a_ TImage If you want you can try BGRABitmap: it has alpha support - and BGRAControls: for example you can use BGRAVirtualScreen to draw the things you want in replace of TPaintBox, or TBGRASpriteAnimation in replace of TImage.. BGRABitmap: http://lazarus.freepascal.org/index.php/board,46.0.html BGRAControls: http://lazarus.freepascal.org/index.php/topic,12411.0.html ---------------------------------------------------------------------- radioman · 2011-09-14 23:46 Thank you for your response. Setting TransparentColor does not do anything. The same weird behaviour. Using Image.Picture.Bitmap.Canvas instead Image.Canvas works, but it is awful slow... Thank you! ---------------------------------------------------------------------- Blaazen · 2011-09-15 00:10 You are using that "one color transparency", right? Canvas.CopyRect does not work with it, only Canvas.Draw can work with this kind of transparency. On the page linked by lainz is described the trick with memstream to activate transparency. Code: [Select]memstream := TMemoryStream.create;   try     bmp.SaveToStream(memstream);     memstream.position := 0;     bmp.LoadFromStream(memstream);   finally     memstream.free;   end; So maybe you can use only one TImage and two TBitmaps (one for map and the second for locations) and draw both these TBitmaps to TImage by Canvas.Draw ---------------------------------------------------------------------- radioman · 2011-09-15 15:53 Thank you for the idea!