LEAD Technologies, Inc

PNG Files and Transparency

Images may or may not contain transparency. The transparent color is a RGB color for images that are not palettized (> 8 bits per pixel). For palettized images, the transparent color is an index to a color within the palette.

PNG supports transparent images that have one or more transparent colors. However, currently LEADTOOLS cannot handle more than one transparent color. Therefore, the first transparent color encountered by LEADTOOLS is used as the transparent color for the image.

When loading PNG images that have transparency, LEADTOOLS sets RasterImage.Transparent to 1 and sets RasterImage.TransparentColor to the transparent color. Please note that if the loaded PNG image is not palettized, then RasterImage.TransparentColor is set to an RGB color. If the loaded PNG image is palettized, RasterImage.TransparentColor is set to 0x010000XX, where XX is the index of the transparent color.

When an image that contains transparency (i.e. RasterImage.TransparentColor is set) is saved as PNG, the transparency information is saved automatically. This is true for all images, regardless of their bits/pixel.

Please note that some developers consider the alpha channel to contain transparency information. LEADTOOLS does not make that assumption. Transparency is implemented in LEADTOOLS as explained above. You can handle the alpha channel information using the Alpha channel methods.

Some PNG files have an 8-bit palettized component (for the image) and 8-bit alpha information. For these files, CodecsImageInfo.BitsPerPixel is 8 and CodecsImageInfo.HasAlpha is set. By default (when passing 0 for nBitsPerPixel when calling the load methods), the image is loaded as 8 bits (the alpha information is ignored). To get the alpha information from these files, you need to load the image as 32 or 64-bit. In this case, the alpha information will be loaded in the alpha channel. LEADTOOLS does not save these 8+8 files.

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.