背景
构建自定义FireMonkey GUI控件。我想将控件呈现给后台缓冲区。后台缓冲区将在控件的画布上绘制。
后台缓冲区是Fmx.TBitmap对象。
我正在使用后台缓冲区,因为控制渲染代码有点牵扯,每次重新绘制控件时都不需要调用。只有当某些控件属性发生更改时,才会更新后台缓冲区。
问题
BackBuffer.Canvas绘图操作没有可见效果。但是,清除位图或单独设置位图像素的值可以按预期工作。
由于某种原因,BackBuffer.Canvas对象不会在后缓冲区位图上绘制。
如果包含一些线索,我已经提取了相关代码。
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;
答案 0 :(得分:4)
尝试使用以下方式包围您的绘图:
BackBuffer.Canvas.BeginScene;
..
..
BackBuffer.Canvas.EndScene;
BackBuffer.BitmapChanged;
P.S。我是FireMonkey风格的新手,所以请试一试,如果有效的话请写下来!