How to mix canvas and LazFreeType lazarus / 39-Graphics ---------------------------------------------------------------------- oraculus · 2015-02-16 17:30 Hello folks: I need to develop a program that mix Canvas and LazFreeType in any order, for example a Line, a Ellipse, a LazFreetype font, a new Ellipse, etc. I only manage to do it if I draw all the LazFreetype fonts first, and all the ellipses, lines, etc., secondly. I need to do it in any order and any mixing way. Here is my code example: Code: [Select]... uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,   StdCtrls, LCLIntf, LCLType, fpimage,   IntfGraphics, GraphType,      //Intf basic routines   EasyLazFreeType,  LazFreeTypeIntfDrawer;  //EasyFreeType with Intf                                      ... type   { TForm1 }   TForm1 = class(TForm)     BtnHaz: TButton;     Bmp: TImage;     procedure BtnHazClick(Sender: TObject);   end; var   Form1: TForm1; ... procedure TForm1.BtnHazClick(Sender: TObject); var   bmp2: TBitmap;   lazimg: TLazIntfImage;   drawer: TIntfFreeTypeDrawer;   ftFont1: TFreeTypeFont; begin   bmp2 := TBitmap.Create;   lazimg := TLazIntfImage.Create(0,0, [riqfRGB]);   drawer := TIntfFreeTypeDrawer.Create(lazimg);   ftFont1 := nil;   ftFont1 := TFreeTypeFont.Create;   ftFont1.Name := 'AstroGadget.ttf';   ftFont1.SizeInPoints := 27;   lazimg.SetSize(Form1.bmp.Width,Form1.bmp.Height);   drawer.FillPixels(TColorToFPColor(clWhite));   ftFont1.Hinted := true;   ftFont1.ClearType := true;   ftFont1.Quality := grqHighQuality;   ftFont1.SmallLinePadding := false;   SetBkMode(bmp2.Canvas.Handle, TRANSPARENT);   bmp2.Canvas.Ellipse(10,10,90,90); // <- Here don't work   drawer.DrawTextRect('ABCDEFGHIJKLM', ftFont1, 0,0, 350,90,     colBlack, [ftaLeft, ftaBottom]);// <- Here work   bmp2.LoadFromIntfImage(lazimg);   bmp2.Canvas.Brush.Style := bsClear;   bmp2.Canvas.Ellipse(10,10,90,90); // <- Here work   drawer.DrawTextRect('ABCDEFGHIJKLM', ftFont1, 0,0, 350,90,     colBlack, [ftaLeft, ftaBottom]); // Here don't work   Form1.bmp.Canvas.Draw(0, 0, bmp2);// bmp2 -> bmp   bmp2.Free; end;        ... Thank-you very much for your help ---------------------------------------------------------------------- engkin · 2015-02-16 20:32 bmp2 is a memory representation, drawing on it will not show anything visible until you copy its contents to the real visible image at the end: Code: [Select]  Form1.bmp.Canvas.Draw(0, 0, bmp2);// bmp2 -> bmp ---------------------------------------------------------------------- oraculus · 2015-02-16 21:27 Thank-you engkin. That you say, is exactly the same that I do in my code. But this is not my question. ---------------------------------------------------------------------- oraculus · 2015-02-20 10:31 Finally I discover a solution with TBGRABitmap. Here are the source code: Code: [Select]... uses   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,   StdCtrls, LCLIntf, LCLType, fpimage,   BGRABitmap,BGRABitmapTypes, //BGRABitmap   BGRAFreeType,               //BGRABitmap FreeType support   EasyLazFreeType; type   { TForm1 }   TForm1 = class(TForm)     BtnHaz: TButton;     Bmp: TImage;     procedure BtnHazClick(Sender: TObject);   end; var   Form1: TForm1;  ... procedure TForm1.BtnHazClick(Sender: TObject); var   bmp2: TBGRABitmap; //TBitmap;   drawer: TBGRAFreeTypeDrawer;   ftFont1: TFreeTypeFont; begin   bmp2 := TBGRABitmap.Create(Form1.bmp.Width,Form1.bmp.Height,ColorToR GB(clBtnFace));   ftFont1 := TFreeTypeFont.Create;   ftFont1.Name := 'AstroGadget.ttf';   ftFont1.SizeInPoints := 27;   SetBkMode(bmp2.Canvas.Handle, TRANSPARENT);   bmp2.Fill(ColorToBGRA(ColorToRGB(clWhite)));   drawer := TBGRAFreeTypeDrawer.Create(bmp2);   ftFont1.Hinted := true;   ftFont1.ClearType := true;   ftFont1.Quality := grqHighQuality;   ftFont1.SmallLinePadding := false;   bmp2.Canvas.Ellipse(10,10,80,90);   drawer.DrawText('ABCDEFGHIJKLM',ftFont1,0,0,BGRABlack,[ftaTop,ftaLef t]);   bmp2.Canvas.Brush.Style := bsClear;  // Transparent   bmp2.Canvas.Ellipse(50,10,120,90);   bmp2.Draw(Canvas,0,0);   bmp2.Free;   drawer.Free;   ftFont1.Free; end;            ...