Recent

Author Topic: Question about BGRAGraphicControl  (Read 1931 times)

stab

  • Full Member
  • ***
  • Posts: 234
Question about BGRAGraphicControl
« 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? %)
« Last Edit: January 22, 2022, 11:43:21 am by stab »

circular

  • Hero Member
  • *****
  • Posts: 3799
    • Personal webpage
Re: Question about BGRAGraphicControl
« Reply #1 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.
Conscience is the debugger of the mind

stab

  • Full Member
  • ***
  • Posts: 234
Re: Question about BGRAGraphicControl
« Reply #2 on: January 29, 2022, 02:04:14 pm »
Thank you for your explanation.

circular

  • Hero Member
  • *****
  • Posts: 3799
    • Personal webpage
Re: Question about BGRAGraphicControl
« Reply #3 on: January 29, 2022, 06:23:18 pm »
You're welcome.  :-*
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018