2013-04-13 66 views
2

如何在Firemonkey应用程序中绘制位图高质量文本?在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); 
+0

fmx中的高质量文本?不是fmx以....... –

+0

而闻名的东西但是,当我用我的语言(波斯语)文字显示质量差的字符! – sma6871

+0

是的,fmx以其质量较差的文字而闻名 –

回答

0

当您在画布上绘画而不是绘画方法时,您需要使用startscene和endscene环绕绘图命令。

所以,你的代码之前添加一行:

imgStory.canvas.beginscene; 

和你的代码之后:

imgStory.canvas.endscene; 
+0

没有效果! – sma6871

+0

对不起,错过了它是一个Timage而不是位图。您需要将图像加载到Timage或创建一个空白的图像。然后在imgstory.bitmap.canvas上绘制。将发布一个新的答案,因为我不能解决如何格式化代码的评论。 –

3

因此,它需要加载或首先创建一个位图,然后绘制位图上的一个TImage中。您还需要绘图命令周围的startscene和endcene。从文件创建位图:

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 
+0

FillText不使用笔画属性。它只使用画布的填充属性。所得到的文本充其量也看起来令人沮丧。 – nurettin

0

我知道这是一个老问题,但我偶然发现了它,并在我的最后努力。这是我的代码。我想也许这是你设定的方式。我不认为只要调用.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;