Lazarus

Programming => Graphics => Graphics and Multimedia => BGRABitmap and LazPaint => Topic started by: stab on January 22, 2022, 12:02:17 am

Title: Question about BGRAGraphicControl
Post by: stab on January 22, 2022, 12:02:17 am
Would like to be able to draw with antialiasing and wonder if it possible to draw on the CanvasBGRA of a BGRAGraphicControl like on a Canvas.
I see there is a Bitmap of type TBGRABitmap and tried:

procedure TForm1.Button1Click(Sender: TObject);
begin
  BGRAGraphicControl1.Bitmap.CanvasBGRA.Brush.Color := clWhite;
  BGRAGraphicControl1.Bitmap.CanvasBGRA.FillRect(0, 0,
    BGRAGraphicControl1.Width, BGRAGraphicControl1.Height);
  BGRAGraphicControl1.Bitmap.CanvasBGRA.Pen.Color := clRed;
  BGRAGraphicControl1.Bitmap.CanvasBGRA.Line(0, 0, 50, 50);
end;

But nothing was drawn.


How could one use the CanvasBGRA to draw in the same way as
on a Canvas or is the only way to use it to do as in tutorial 13? %)
Title: Re: Question about BGRAGraphicControl
Post by: circular on January 29, 2022, 12:31:51 pm
When you draw on the BGRABitmap attached to the BGRAGraphicControl1, it does not trigger the update of the GUI. You need to call BGRAGraphicControl1.Invalidate for that.

Though BGRAGraphicControl1 is intended to be used like this:
- set some variable to define the state ("with a red line" in this case)
- call RedrawBitmap or InvalidateBitmap function
- in the OnRedraw event, render the image according to the state variable

This way, if the component were to be resized, you would still have a correctly rendered image. Also you would not have a problem of uninitialized bitmap if there is something to be drawn when the form is shown for the first time.
Title: Re: Question about BGRAGraphicControl
Post by: stab on January 29, 2022, 02:04:14 pm
Thank you for your explanation.
Title: Re: Question about BGRAGraphicControl
Post by: circular on January 29, 2022, 06:23:18 pm
You're welcome.  :-*
TinyPortal © 2005-2018