Search code examples
delphipngdelphi-2007bmpimage-conversion

Save Bitmap with transparency to PNG in Delphi 2007


I have a Delphi bitmap (32Bit) that has transparency information. I need to convert and save it to a PNG file while preserving the transparency.

The tools I currently have are the graphics32 Library, GR32_PNG (by Christian Budde), and PNGImage (by Gustavo daud).

What is the best way to do this?

EDIT 1 : There is not just one color in my bitmap that's transparent but pixels with varying levels of transparency that needs to be preserved.

EDIT 2 : I am getting my bitmap with alpha information by setting the background of an image to a PNG I have with nothing but an empty alpha layer. Then I write anti-aliased text onto it. I then save the bitmap. When opened with gimp it show the transparency and upon zooming in you can see the effect of anti-aliasing.


Solution

  • I could not get either of the other two answer to work. They may work for others but here is what I did.

    1. I created the bitmap with transparency.
    2. Assigned it to a TBitmap32 from the Graphics 32 library.
    3. Assigned it to a TPortableNetworkGraphics32 from Christian Budde's GR32_PNG for Graphics32
    4. Called the TPortableNetworkGraphics32.SaveToFile method