Draw text in a PNG with text color lazarus / 39-Graphics ---------------------------------------------------------------------- Prodigy · 2013-02-10 15:04 How to draw a text in a PNG with text color (and text background transparent)? This do not work: Code: [Select]  PNG := TPortableNetworkGraphic.Create;   PNG.LoadFromFile(...);   PNG.Canvas.Font.Size:=18;   PNG.Canvas.Font.Name:='Arial';   PNG.Canvas.Font.Color :=clRed;   PNG.Canvas.Brush.Style:=bsClear;   PNG.Canvas.TextOut(50,50,'A');   Image1.Picture.Assign(PNG); ---------------------------------------------------------------------- vrull · 2013-03-13 19:54 I think only TBitmap is supported enough to draw on its canvas.  Try to assign your PNG to a TBitmap object, paint on bitmap canvas, then assign the result back to PNG. ---------------------------------------------------------------------- Ocye · 2013-03-14 08:49 This works perfect: Code: [Select]  with TPortableNetworkGraphic.Create do   try     Width:=50;     Height:=50;     Canvas.TextOut(1,1,'A');     SaveToFile('test.png');   finally     Free;   end; Is 50,50 perhaps outside your canvas? ---------------------------------------------------------------------- Prodigy · 2013-03-27 04:24 Quote from: Ocye on March 14, 2013, 09:49:51 amThis works perfect: Code: [Select]  with TPortableNetworkGraphic.Create do   try     Width:=50;     Height:=50;     Canvas.TextOut(1,1,'A');     SaveToFile('test.png');   finally     Free;   end; Is 50,50 perhaps outside your canvas? Where is text color? 50,50 is inside my canvas. Edit: When the image has transparent color Textout() and TextRect() always generate white text. Why? ---------------------------------------------------------------------- Prodigy · 2013-03-29 05:02 My code works (help from this post: http://forum.lazarus.freepascal.or g/index.php/topic,15496.msg83321.html#msg83321): Code: [Select]var   LImg, LImgT: TLazIntfImage;   PNG: TPortableNetworkGraphic;   PNGText: TPortableNetworkGraphic;   x, y: Integer;   TextColor: TColor; begin   TextColor := clBlue;   PNG := TPortableNetworkGraphic.Create;   PNG.LoadFromFile('...');   PNGText := TPortableNetworkGraphic.Create;   PNGText.PixelFormat:=pf32bit;   PNGText.Canvas.Brush.Color:=clWhite;  //do not change   PNGText.Canvas.Font.Color:=clBlack; //do not change   PNGText.SetSize(PNGText.Canvas.TextWidth('X'),PNGText.Canvas.TextHei ght('X'));//your Text   PNGText.Canvas.FillRect(Rect(0,0,PNGText.Width,PNGText.Height));   PNGText.Canvas.TextOut(0,0,'X'); //your Text   LImgT := PNGText.CreateIntfImage;   LImg := PNG.CreateIntfImage;   for x:=0 to LImgT.Width-1 do     for y:=0 to LImgT.Height-1 do       if LImgT.Colors[x,y].Red<>High(Word) then         LImg.Colors[50+x,50+y]:=TColorToFPColor(TextColor);   PNG.LoadFromIntfImage(LImg);   LImgT.Free;   LImg.Free;   PNG.SaveToFile('test.png');