Recent

Author Topic: Problem to save image (in PNG) with transparency  (Read 2627 times)

carlejt

  • New Member
  • *
  • Posts: 39
Problem to save image (in PNG) with transparency
« on: January 06, 2012, 11:20:11 pm »
Problem to save image (in PNG) with transparency;
I do not know how to do it, I tried this (but have not had the expected result):

Code: [Select]

procedure TForm1.Button1Click(Sender: TObject);

var png: TPortableNetworkGraphic;

begin

  png:=TPortableNetworkGraphic.Create;
  png.Width:=200;
  png.Height:=200;

  png.Transparent:=true;
  png.TransparentColor:=clYellow;  // transparent color

  png.Canvas.Brush.Color:=clblue;
  png.Canvas.FillRect(0,0,199,199);
  png.Canvas.Brush.Color:=clyellow;
  png.Canvas.FillRect(50,50,150,150);

  png.SaveToFile('image.png');    // why the image has no transparency?

end;



How to save the image in PNG with transparency?, Is it possible?, What is the solution?

Thanks.

Wodzu

  • Full Member
  • ***
  • Posts: 171
Re: Problem to save image (in PNG) with transparency
« Reply #1 on: January 08, 2012, 09:06:36 pm »
Strange, I've played with it for a while and also could not get transparency to work.

Interesting thing is that when you modify PixelFormat property to 32bit, the blue border is getting transparent.

 

TinyPortal © 2005-2018