2
votes

How I can Draw Bitmap high quality text in firemonkey application?

I have an TImage in my form with imgStory name.

I tried this code but it does not worked and imgStory still show blank!

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);
3
High quality text in fmx? Not something that fmx is renowned for.......David Heffernan
But when I use text in my language (Persian) the characters shows in bad quality!!sma6871
Yes, fmx is well know for its poor quality textDavid Heffernan

3 Answers

3
votes

So its a Timage that requires loading or creating a bitmap first and then drawing on the bitmap. You also need the beginscene and endscene around the drawing commands. To create the bitmap from a file:

imgstory.bitmap.createfromfile(filename);

or you can create a blank one:

imgstory.bitmap.create(width,height);

Then the drawing becomes:

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
1
votes

I know this is an old questions, but I came across it, and got it working on my end. Here is my code. I think maybe it was the way you were setting up mrect. I don't think just calling the .create() function without setting the output to a variable will work.

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;
0
votes

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;