修复:android上使用fmx字体的canvas.filltext被块背景包围
固定见答案 我找到了关于如何使用firemonkey获取文本的帖子。我有一个图形图像,我想把它的标签。我使用了.filltext并用win32进行了测试,一切都很好。但是当我在安卓上运行时,文本只是背景上的白色块。显然,我需要设置字体使用的画笔,但我不清楚如何设置。(我已通过android缩放正确调整位图大小,我的drawpolygon工作正常) 代码段如下修复:android上使用fmx字体的canvas.filltext被块背景包围,android,delphi,text,bitmap,firemonkey,Android,Delphi,Text,Bitmap,Firemonkey,固定见答案 我找到了关于如何使用firemonkey获取文本的帖子。我有一个图形图像,我想把它的标签。我使用了.filltext并用win32进行了测试,一切都很好。但是当我在安卓上运行时,文本只是背景上的白色块。显然,我需要设置字体使用的画笔,但我不清楚如何设置。(我已通过android缩放正确调整位图大小,我的drawpolygon工作正常) 代码段如下 Image1.bitmap.Canvas.BeginScene; Image1.bitmap.canvas.Clear(TAlph
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;
底线是。。。如果您在android上使用filltext,则文本颜色和周围的背景设置如下:
Image1.bitmap.Canvas.Fill.Color := TAlphaColors.Yellow;//text color
Image1.Bitmap.Canvas.Fill.DefaultColor:=TAlphaColors.black; //background
这与win32平台不同,在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;
Tom,这段代码正在开发中,并从多个来源中删除和修改。在文章底部添加了注释和详细信息。。。。