PNG Files and Transparency
Bitmaps may or may not contain transparency. The transparent color is a RGB color for bitmaps that are not palettized (> 8 bits per pixel). For palettized bitmaps, the transparent color is an index to a color within the palette.
PNG supports transparent bitmaps 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 bitmap.
When loading PNG bitmaps that have transparency, LEADTOOLS sets the BitmapEnableTransparency property to TRUE and BitmapTransparentColor property to the transparent color. Please note that if the loaded PNG bitmap is not palettized, then the BitmapTransparentColor property is set to an RGB color. If the loaded PNG bitmap is palettized, the BitmapTransparentColor property is set to 0x010000XX, where XX is the index of the transparent color.
When a bitmap that contains transparency (i.e. BitmapEnableTransparency property is set to TRUE) is saved as PNG, the transparency information is saved automatically. This is true for all bitmaps, regardless of their bits/pixel.
Please note that some developers consider the alpha channel to contain transparency information. Transparency is implemented in LEADTOOLS as explained above. However, FeatherAlphaBlend and FeatherAlphaBlendExt are powerful methods that can be used to implement transparency, using a mask saved as an alpha channel. If a bitmap contains a transparency mask in the alpha channel, call BitmapAlpha property to get the alpha channel information back into a bitmap form. Once the transparency mask information is in a bitmap, it can be passed directly to the FeatherAlphaBlend method or FeatherAlphaBlendExt method as the mask. For sample code that demonstrates how to do this, refer to Implementing Transparency. For more information on functions that utilize alpha channel information, refer to Working with the Alpha Channel.If a PNG file contains an alpha bitmap, the InfoHasAlpha property will be set to TRUE when the GetFileInfo method is called. You can access the alpha channel information through the BitmapAlpha property.
Some PNG files have an 8-bit palettized component (for the image) and 8-bit alpha information. When you get the information for these files, InfoBits property gets set to 8 and the InfoHasAlpha property gets set to TRUE. By default (when passing 0 for iBitsPerPixel to 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 can be accessed with the BitmapAlpha property. LEADTOOLS does not save these 8+8 files.