Firemonkey:TBitmap.Canvas 绘图方法没有可见结果。我做错了什么?
背景
我正在构建一个自定义 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;
Background
I/m building a custom FireMonkey GUI control. I want to render the control to a back buffer. The back buffer will be drawn on the control's canvas.
The back buffer is a Fmx.TBitmap object.
I am using a back buffer because the control rendering code is a little involved and does not need to be called each time the control is repainted. The back buffer will only be updated when some control properties change.
Problem
The BackBuffer.Canvas drawing operations have no visible effect. However clearing the bitmap, or setting the value of the bitmap pixels individually do work as expected.
For some reason the BackBuffer.Canvas object will not draw on the back buffer bitmap.
- I think I've set the required Canvas.Fill properties correctly.
- All the canvas properties I've checked appear to be correct. (Canvas width/height/etc)
I've extracted the relevant code in case that contains some clues.
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试用以下内容包围您的绘图:
PS 我对 FireMonkey 风格还很陌生,所以只要尝试一下并写下它是否有效!
Try surrounding your drawing with:
P.S. I'm pretty new with FireMonkey style, so just try it out and write if it worked please!