背景 我/我构建一个自定义的FireMonkey GUI控件.我想将控件呈现给后台缓冲区.后台缓冲区将在控件的画布上绘制. 后台缓冲区是Fmx.TBitmap对象. 我正在使用后台缓冲区,因为控制渲染代码涉及
我/我构建一个自定义的FireMonkey GUI控件.我想将控件呈现给后台缓冲区.后台缓冲区将在控件的画布上绘制.
>后台缓冲区是Fmx.TBitmap对象.
>我正在使用后台缓冲区,因为控制渲染代码涉及很少,每次重新绘制控件时都不需要调用.只有当某些控件属性发生更改时,才会更新后台缓冲区.
问题
BackBuffer.Canvas绘图操作没有可见效果.但是,清除位图或单独设置位图像素的值可以按预期工作.
由于某种原因,BackBuffer.Canvas对象不会在后缓冲区位图上绘制.
>我想我已经正确设置了所需的Canvas.Fill属性.
>我检查的所有画布属性似乎都是正确的. (画布宽度/高度/等)
在包含一些线索的情况下,我已经提取了相关代码.
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;尝试围绕您的绘图:
BackBuffer.Canvas.BeginScene; .. .. BackBuffer.Canvas.EndScene; BackBuffer.BitmapChanged;
附:我是FireMonkey风格的新手,所以试试吧,如果它有效请写!