Author Topic: [SOLVED] BGRABitmap and transparency  (Read 2377 times)


  • Jr. Member
  • **
  • Posts: 67
[SOLVED] BGRABitmap and transparency
« on: May 02, 2017, 06:32:43 pm »
Hi All

Thanks in advance for any assistance!

I am using Laz to code a little pixel graphics editor. I have 4 BGRABitmaps.

1] A Zoomed view of enlarged 64x64 pixels.
2] An actual cell size of 64X64 Pixels {view actual size}
3] A BGRABitmap (512x512) of all the (64x64) cells.
4] A Current Cell Indicator (green rectangle with transparency)

So what I currently have:
User paints a pixel in the zoomed view. This is reflected in both the Actual Size bitmap and ALLCELLS bitmap in real time. All works smoothly!

However, I want there to be another bitmap (Cell Indicator) which is over bitmap 3 showing the cell bounds being painted. However, whenever I do this I get really bad flicker.

Here is the Bitmap Creation Code:
Code: Pascal  [Select][+][-]
  1.   AllCharsBmp:=TBGRABitmap.Create(512,512, BGRA(tPaintCol.Red, tPaintCol.Green, tPaintCol.Blue, tPaintCol.Alpha) );
  2.         //AllCharsGrid:=TBGRABitmap.Create(512,512, BGRAPixelTransparent );
  3.   SelectBmp:=TBGRABitmap.Create(64,64,BGRAPixelTransparent);
  4.   SelectBmp.Canvas.Pen.Color:=BGRA(0,255,0,128);
  5.   SelectBmp.Canvas.Pen.Style:=psDash;
  6.   SelectBmp.DrawHorizLine(0,0,63, BGRA(0,255,0,128));
  7.   SelectBmp.DrawHorizLine(0,63,63, BGRA(0,255,0,128));

and on the MouseMove event I draw the bitmaps like so:
Code: Pascal  [Select][+][-]
  1.       AllCharsBmp.Draw(CharImagePanel.Canvas,8,8,true);
  4.     end;
  6.     MainPaintBmp.Draw(MainPaintPanel.Canvas,8,8);
  7.     SelectBmp.Draw(CharImagePanel.Canvas,8,8, True);

How do I stop the flicker? Should I move all drawing to the onPaint event for the canvas in question?

What I want is the SelectBmp to be shown whilst real time drawing is shown on the bitmap underneath, but with no flicker?

Any help greatly appreciated.

Thanks  :D

« Last Edit: May 07, 2017, 10:11:59 pm by JasonLugg »


  • Hero Member
  • *****
  • Posts: 3593
    • Lainz
Re: BGRABitmap and transparency
« Reply #1 on: May 02, 2017, 08:12:32 pm »
Draw everything on paint event. - My Website - LazPaint Downloads


  • Hero Member
  • *****
  • Posts: 3341
    • Personal webpage
Re: BGRABitmap and transparency
« Reply #2 on: May 02, 2017, 08:37:29 pm »
You can use TBGRAVirtualScreen and draw things in the OnRedraw event. That would avoid any flickering. In the OnMouseMove event, call DiscardBitmap.

Note that setting pen style in the Canvas property does not work here because you are not using drawing functions of Canvas. Anyway you should use CanvasBGRA if you want to set pen style this way and the drawing function provided in CanvasBGRA.
Conscience is the debugger of the mind


TinyPortal © 2005-2018