Firemonkey: TBitmap.Canvas drawing methods have no visible results. What am I doing wrong?

Background

I / m creates a custom FireMonkey GUI control. I want to display the control in a reverse buffer. The reverse buffer will be drawn on the control canvas.

  • The back buffer is an Fmx.TBitmap object.

  • I use the back buffer because the control rendering code is a bit involved and does not need to be called every time the control is redrawn. The back buffer will only be updated after changing some control properties.

Problem

BackBuffer.Canvas drawing operations have no visible effect. However, clearing a bitmap or setting bitmap pixels individually works properly.

For some reason, the BackBuffer.Canvas object will not draw a bitmap for the back buffer.

  • I think I set the Canvas.Fill properties correctly.
  • All the properties of the canvas that I checked look correct. (Width / height of the canvas, etc.)

I extracted the appropriate code in case it contains some hints.

TMyControl(TControl) private protected BackBuffer : TBitmap; procedure Paint; override; procedure Resize; override; public constructor Create(AOwner: TComponent); override; end; constructor TMyControl.Create(AOwner: TComponent); begin inherited; BackBuffer := TBitmap.Create(10, 10); end; procedure TFxSampleDisplay.Resize; var w, h : integer; begin inherited; // Ensure BackBuffer is the same size as the control. w := round(BoundsRect.Width); h := round(BoundsRect.Height); BackBuffer.SetSize(w,h); end; procedure TMyControl.Paint; var r : TRectF; begin inherited; //******** This has visible results ******** BackBuffer.Clear($1100ff00); // Fill with semi-opaque green background BackBuffer.Pixels[2,2] := $ffff0000; // Draw a red pixel //******** This doesn't have visible results ******** r.Left := 0; r.Top := 0; r.Right := 50; r.Bottom := 50; BackBuffer.Canvas.Fill.Color := $ffff0000; // Set fill to RED. BackBuffer.Canvas.Fill.Kind := TBrushKind.bkSolid; BackBuffer.Canvas.FillRect(r, 10,10, AllCorners, 1); //******** Draw the backbuffer on to the controls canvas ******** Canvas.DrawBitmap(BackBuffer, BoundsRect, BoundsRect, 1); end; 
+4
source share
1 answer

Try to surround your drawing:

 BackBuffer.Canvas.BeginScene; .. .. BackBuffer.Canvas.EndScene; BackBuffer.BitmapChanged; 

PS I am new to FireMonkey style, so just try and write, if that worked, please!

+4
source

Source: https://habr.com/ru/post/1384031/


All Articles