修复:android上的canvas.filltext与fmx字体被块背景包围

时间:2017-08-01 02:29:22

标签: android delphi text bitmap firemonkey

修好了看答案。

我找到了有关如何使用firemonkey处理文本的帖子。我有一个图形图像,我想在上面贴上标签。我使用.filltext并测试了win32,一切都很好。但是当我在Android上运行时,文本只是背景上的白色块。显然我需要设置字体正在使用的画笔,但我不清楚如何。 (我已经通过android缩放正确调整了位图的大小,并且我的drawpolygon按预期工作)

代码的细分如下。

  Image1.bitmap.Canvas.BeginScene;
  Image1.bitmap.canvas.Clear(TAlphaColors.Black);
  Image1.bitmap.Canvas.Stroke.Thickness := 1;
  Image1.bitmap.Canvas.Stroke.Color := TAlphaColorRec.Yellow;
  Image1.bitmap.Canvas.DrawPolygon(FPoints2, 1);               // polygon
  // now testing text
    Canvas.Font.Size := 40;
   Image1.bitmap.mRect.Create(0, 0, (image1.width),( image1.height));
   Image1.bitmap.Canvas.filltext(mRect, 'Hello Text!', false, 1,
        [TFillTextFlag.RightToLeft],TTextAlign.Center, TTextAlign.Trailing);
   Image1.bitmap.Canvas.EndScene;

1 个答案:

答案 0 :(得分:2)

底线...如果您在android上使用filltext,文本颜色及其周围的背景设置如下:

Image1.bitmap.Canvas.Fill.Color := TAlphaColors.Yellow;//text color
Image1.Bitmap.Canvas.Fill.DefaultColor:=TAlphaColors.black; //background

这与win32平台不同,其中Image1.bitmap.Canvas.Stroke.Color设置文本颜色,并且文本周围看起来有透明背景......

所以对于其他任何打击这些东西的人来说,在android和win32上都有代码。如果某人有有用的评论,我将非常感谢他们,特别是能够将背景设置为透明的必须记录。我无法在互联网上的任何地方找到这些信息。谢谢罗伯特

procedure TMainFrm.draw_waveform;
var 
  mrect:trect;     //yellow waveform on black background with yellow text

begin
   waveformunit.init(image1);  // the two steps commented below done elsewhere
   // VERY important to do this for android otherwise it doesn't work!!!
   // Image.Bitmap.SetSize(Trunc(Image.Width * Image.Canvas.Scale),
                               //  Trunc(Image.Height * Image.Canvas.Scale));
   //   Image.Bitmap.canvas.Clear(TAlphaColors.black);
   to_polygon;

   Image1.bitmap.Canvas.BeginScene;
   Image1.Bitmap.canvas.Clear(TAlphaColors.black);
   Image1.bitmap.Canvas.Stroke.Thickness := 1;
   Image1.bitmap.Canvas.Stroke.Color := TAlphaColorRec.Yellow; //polygon line color
   Image1.bitmap.Canvas.DrawPolygon(FPoints2, 1);               // polygon
   //now test text
   Image1.Bitmap.canvas.Stroke.Kind := TBrushKind.bkSolid;
   Image1.Bitmap.canvas.Stroke.Thickness := 1;
   Image1.bitmap.Canvas.Fill.Color := TAlphaColors.Yellow;     //text color
   Image1.Bitmap.Canvas.Fill.DefaultColor:=TAlphaColors.black; // to match background
   Image1.Bitmap.Canvas.Font.Size:=36;
   Image1.Bitmap.Canvas.Font.Family:='Arial';
   Image1.Bitmap.Canvas.Font.Style:=[TFontStyle.fsbold];
   Image1.bitmap.canvas.Blending:=false;
   Image1.bitmap.Canvas.Font.Size := 40;
        mRect.Create(0, 0,round(image1.width),round( image1.height));
   Image1.bitmap.Canvas.filltext(mRect, 'Hello Text!', false, 1,
         [TFillTextFlag.RightToLeft],TTextAlign.Center, TTextAlign.Trailing);
   Image1.bitmap.Canvas.EndScene;

  //inc(numberdrawn);
end;