2017-08-01 3 views
1

fixe voir la réponse.Correction: canvas.filltext sur android avec la police fmx est entourée par les arrière-plans de bloc

J'ai trouvé les messages sur la façon d'obtenir du texte travaillant avec firemonkey. J'ai une image graphique et je veux y mettre une étiquette. J'ai utilisé .filltext et testé avec Win32 et tout a bien fonctionné. Mais quand j'ai couru sur l'androïde le texte est juste des blocs de blanc sur le fond. Évidemment, j'ai besoin de définir la brosse que la police utilise, mais ce n'est pas clair pour moi comment. (J'ai correctement dimensionné le bitmap via la mise à l'échelle android et mon drawpolygon fonctionne comme prévu)

Le segment du code est ci-dessous.

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

Tom, ce code est le développement et levé et modifié à partir de plusieurs sources. – rebible

+0

a ajouté des commentaires et des détails au bas de l'article .... – rebible

Répondre

1

Bottom line ... Si vous utilisez filltext sur l'androïde la couleur du texte et l'arrière-plan autour d'elle sont définies comme telles:

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

Ceci est différent de la plate-forme win32 où Image1.bitmap.Canvas.Stroke.Color ensembles la couleur du texte et il semble avoir un fond transparent autour du texte ...

Donc, pour quelqu'un d'autre qui combat ce genre de choses est le code de travail sur android et win32. Si quelqu'un a des commentaires utiles, je les apprécierais, surtout en étant capable de définir l'arrière-plan comme transparent doit être documenté. Je n'ai pas trouvé cette information nulle part sur internet. merci robert

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;