Sign in Join
Wiki copytemporary

Revision 1 of 2, by WikiArchive on 11-4-2026. The page as it is now.

BGRABitmap tutorial 12/fr

Accueil | Tutoriel 1 | Tutoriel 2 | Tutoriel 3 | Tutoriel 4 | Tutoriel 5 | Tutoriel 6 | Tutoriel 7 | Tutoriel 8 | Tutoriel 9 | Tutoriel 10 | Tutoriel 11 | Tutoriel 12 | Edit

Ce tutoriel montre comment utiliser les fonctions texte par défaut. Pour les fonctions avancées, voir les moteurs de rendu.

Contents

Texte simple

Vous pouvez dessiner un texte simple comme cela :

pascal
procedure TForm1.FormPaint(Sender: TObject);
    var
      image: TBGRABitmap;
      c: TBGRAPixel;
    begin
      image := TBGRABitmap.Create(ClientWidth,ClientHeight, ColorToBGRA(ColorToRGB(clBtnFace)) );
      c := ColorToBGRA(ColorToRGB(clBtnText)); //retrieve default text color
    
      image.FontHeight := 30;
      image.FontAntialias := true;
      image.FontStyle := [fsBold];
      image.TextOut(ClientWidth-5,5,'Hello world',c,);
      image.SetPixel(5,5,c);
    
      image.Draw(Canvas,0,0,True);
      image.free;
    end;

Ici, la taille de police est de 30 pixels, avec anticrénelage. Utiliser l'anticrénelage pour le texte est plus lent mais plus joli.

Le coin en haut à gauche du texte est aux coordonnées (5,5). Cette origine est montrée avec un SetPixel.

BGRATutorial12a.png

Utiliser l'alignement

Remplacez les TextOut et SetPixel par :

pascal
image.TextOut(ClientWidth-5,5,'Hello world',c,taRightJustify);   
      image.SetPixel(ClientWidth-5,5,c);

Maintenant, l'origine est sur le côté droit de la fenêtre, et le texte est aligné sur la droite.

BGRATutorial12b.png

Rotation de texte

Il est aussi facile de dessiner du texte en rotation. Pour cela, utilisez TextOutAngle ou bien la propriété FontOrientation :

pascal
image.TextOutAngle(30,5,-450,'Hello world',c, taLeftJustify);
      image.SetPixel(30,5,c);

L'angle est en dixièmes de degrés et les valeurs positives sont dans le sens inverse des aiguilles d'une montre. Ceci est une convention pour être compatible avec la propriété Orientation de l'objet Font du canevas standard.

BGRATutorial12c.png

Remarquez à présent où est l'origine du texte (le pixel ajouté).

Texte avec retour à la ligne

Il y a une version facile à utiliser de TextRect :

pascal
image.TextRect(rect(5,5,ClientWidth-5,ClientHeight-5),'This is a text that should be word wrapped',taCenter,tlCenter,c);
      image.Rectangle(rect(5,5,ClientWidth-5,ClientHeight-5),c,dmSet);

Les paramètres sont :

BGRATutorial12d.png

Texte avec une ombre

Vous pouvez dessiner un texte avec une ombre floue avec TextShadow de l'unité BGRAGradients :

pascal
var
      image,txt: TBGRABitmap;
      grad: TBGRAGradientScanner;
      c: TBGRAPixel;
    begin
      image := TBGRABitmap.Create(ClientWidth,ClientHeight, ColorToBGRA(ColorToRGB(clBtnFace)) );
      c := ColorToBGRA(ColorToRGB(clBtnText));
    
      txt := TextShadow(ClientWidth,ClientHeight,'Hello world',30,c,BGRABlack,5,5,5);
      image.PutImage(0,0,txt,dmDrawWithTransparency);
      txt.Free;
    
      image.Draw(Canvas,0,0,True);
      image.free;
    end;

La procédure TextShadow crée une image qui contient le texte avec une ombre. Les paramètres sont :

N'oubliez pas de libérer l'image après utilisation.

BGRATutorial12e.png

Texte avec dégradé

Comme les autres fonctions, vous pouvez passer en paramètre un dégradé ou une texture pour remplir le texte. Voici un exemple :

pascal
uses BGRAGradientScanner;
    
    var
      image: TBGRABitmap;
      grad: TBGRAGradientScanner;
    begin
      image := TBGRABitmap.Create(ClientWidth,ClientHeight, ColorToBGRA(ColorToRGB(clBtnFace)) );
    
      grad := TBGRAGradientScanner.Create(BGRA(255,255,0),BGRA(255,0,0),gtLinear,PointF(0,0),PointF(0,35),True,True);
      image.FontHeight := 30;
      image.FontAntialias := true;
      image.FontStyle := [fsBold];
      image.TextOut(6,6,'Hello world',BGRABlack);  //draw a black border
      image.TextOut(5,5,'Hello world',grad);       //draw gradient text 
      grad.free;
    
      image.Draw(Canvas,0,0,True);
      image.free;
    end;

En premier lieu, un dégradé sinusoïdal horizontal est créé, de couleurs jaune et rouge. Il est ensuite utilisé comme texture.

BGRATutorial12f.png

Tutoriel précédent (combiner les transformations)


From the Free Pascal wiki, page "BGRABitmap tutorial 12/fr", as the Internet Archive kept it on 2025-03-20. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.