2

如何在 firemonkey 应用程序中绘制位图高质量文本?

我的TImage表格中有一个imgStory名字。

我试过这段代码,但它不起作用,imgStory 仍然显示空白!

imgStory.Canvas.Stroke.Kind := TBrushKind.bkSolid;
imgStory.Canvas.StrokeThickness := 1;
imgStory.Canvas.Fill.Color := TAlphaColors.Red;
mRect.Create(100, 229, 300, 250);
imgStory.Canvas.FillText(mRect, 'Hello Text!', false, 100, [TFillTextFlag.ftRightToLeft],
TTextAlign.taCenter, TTextAlign.taCenter);
4

3 回答 3

3

所以它是一个需要先加载或创建位图然后在位图上绘制的 Timage。您还需要围绕绘图命令的开始场景和结束场景。从文件创建位图:

imgstory.bitmap.createfromfile(filename);

或者您可以创建一个空白:

imgstory.bitmap.create(width,height);

那么图就变成了:

imgstory.Bitmap.canvas.BeginScene();
imgStory.Bitmap.canvas.Stroke.Kind := TBrushKind.bkSolid;
imgStory.Bitmap.canvas.StrokeThickness := 1;
imgStory.bitmap.Canvas.Fill.Color := TAlphaColors.Red;
mRect.Create(100, 229, 300, 250);
imgStory.bitmap.Canvas.FillText(mRect, 'Hello Text!', false, 100, [TFillTextFlag.ftRightToLeft],
TTextAlign.taCenter, TTextAlign.taCenter);
imgstory.bitmap.Canvas.endscene
于 2013-04-15T12:06:00.107 回答
1

我知道这是一个古老的问题,但我遇到了它,并让它在我的最终工作。这是我的代码。我想这可能是你设置 mrect 的方式。我认为仅调用 .create() 函数而不将输出设置为变量是行不通的。

Image1.Bitmap.canvas.Stroke.Kind := TBrushKind.bkSolid;
Image1.Bitmap.canvas.StrokeThickness := 1;
Image1.bitmap.Canvas.Fill.Color := TAlphaColors.Red;
Image1.Bitmap.Canvas.Font.Size:=36;
Image1.Bitmap.Canvas.Font.Family:='Arial';
Image1.Bitmap.Canvas.Font.Style:=[TFontStyle.fsbold];
ARect := TRectF.Create(100, 229, 400, 270);
Image1.Bitmap.Canvas.BeginScene;
Image1.Bitmap.Canvas.FillText(ARect, 'Hello Text!', false, 100, [], TTextAlign.taCenter);
Image1.Bitmap.Canvas.EndScene;
于 2017-05-05T16:10:14.883 回答
0

When you are drawing on a canvas other than in a paint method, you need to surround the drawing commands with beginscene and endscene.

So add a line before your code:

imgStory.canvas.beginscene;

and after your code:

imgStory.canvas.endscene;
于 2013-04-14T11:47:44.453 回答