Recent

Author Topic: Does Lazarus Suuport transparency with PNG  (Read 6285 times)

BenJones

  • Full Member
  • ***
  • Posts: 121
Does Lazarus Suuport transparency with PNG
« on: May 09, 2013, 07:01:25 am »
Hi, I was wondering does lazarus support the saving of Transparent png files. I tryed loading in a Bitmap with the transparent color set at RGB 255,0,255, the png file saves but no transparency. any ideas of how to get around this?

Here is a sniplet of code I use maybe you guys can see if I gone wrong anywere.
Thanks

Code: [Select]
var
  png : TPortableNetworkGraphic;
  bmp : TBitmap;
begin
  png := TPortableNetworkGraphic.Create;
  bmp := TBitmap.Create;
  bmp.LoadFromFile('c:\out\ben.bmp');
  png.PixelFormat := pf32bit;
  png.Transparent := True;
  png.TransparentColor := RGBToColor(255,0,255);
  png.Assign(bmp);
  png.SaveToFile('c:\out\hello.png');
When Your Dreams Come True.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Does Lazarus Suuport transparency with PNG
« Reply #1 on: May 09, 2013, 09:19:33 am »
That didn't seem to work, but changing it a little did:
Code: [Select]
var
  png : TPortableNetworkGraphic;
  bmp : TBitmap;
begin
  png := TPortableNetworkGraphic.Create;
  png.PixelFormat := pf32bit;
  bmp := TBitmap.Create;
  bmp.PixelFormat := pf32bit;
  bmp.Transparent := True;
  bmp.TransparentColor := RGBToColor(255,0,255);
  bmp.LoadFromFile('d:\netti\temp.bmp');
  png.SetSize(bmp.Width, bmp.Height);
  png.Canvas.Draw(0, 0, bmp);
  png.SaveToFile('d:\netti\temp.png');
  bmp.Free;
  png.Free;
I got rid of assign(), and made the bmp transparent instead.

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Does Lazarus Suuport transparency with PNG
« Reply #2 on: May 09, 2013, 01:03:30 pm »
Try with BGRABitmap. It has full support for PNG. http://wiki.freepascal.org/BGRABitmap

BenJones

  • Full Member
  • ***
  • Posts: 121
Re: Does Lazarus Suuport transparency with PNG
« Reply #3 on: May 09, 2013, 09:24:57 pm »
Thanks User137 seems to work that now.
Dibo I also take a look at BGRABitmap
thanks agian.
When Your Dreams Come True.

 

TinyPortal © 2005-2018