LEADTOOLS Support
Imaging
Imaging SDK Questions
How to differentiate a 32 bit PNG/BMP file with transparency and without
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Wednesday, June 5, 2013 10:34:28 AM(UTC)
Groups: Registered
Posts: 12
Hello,
How do we different differentiate a 32 bit PNG/BMP file with transparency and without? I have attached the zip file containing image files. I tried referencing the value of
BITMAPHANDLE.Flags.Transparency
but the value is zero. Currently we are using LEADTOOLS Raster Imaging Pro version 15.0 toolkit.
Thanks
#2
Posted
:
Wednesday, June 5, 2013 11:50:39 AM(UTC)
Groups: Registered
Posts: 12
#3
Posted
:
Wednesday, June 5, 2013 12:40:35 PM(UTC)
Groups: Registered
Posts: 12
I made some further experimentation and noticed the ff.
For 32 bit PNG/BMP file without transparency, the result of L_GetBitmapAlpha(), fills the BITMAPHANDLE.Addr.Windows.pData with 0xff.
Is the ff. code to test for this?
-------
BOOL w_LTBitmapHandleCached = FALSE ;
if( hLeadBitmap.BitsPerPixel == 32 && hLeadBitmap.Flags.Allocated && ( fileInfo.Flags & FILEINFO_HAS_ALPHA ) ){
BITMAPHANDLE hLeadAlpha ;
(*leadFuncs.pGetBitmapAlpha_fn)(&hLeadBitmap, &hLeadAlpha, sizeof(BITMAPHANDLE));
ULONG* w_LongPtr ;
bool w_Loop = true ;
for( int a = 0; w_Loop && a < hLeadAlpha.Height; a++ ){
for( int b = 0; w_Loop && b < hLeadAlpha.Width; b++ ){
w_LongPtr = ( ULONG* )&hLeadAlpha.Addr.Windows.pData[ a + b*4 ] ;
w_Loop = *w_LongPtr == 0xffffffff ;
} // for
} // for
(*leadFuncs.pFreeBitmapfn)(&hLeadAlpha);
if( !w_Loop ){
*hLTBitmap = new BITMAPHANDLE ;
memcpy( *hLTBitmap, &hLeadBitmap, sizeof( hLeadBitmap ) ) ;
w_LTBitmapHandleCached = TRUE ;
} // if
} // if
-------
#4
Posted
:
Thursday, June 6, 2013 4:39:54 AM(UTC)
Groups: Registered, Tech Support
Posts: 179
If you want to know if the image has a alpha image with transparency by code, the easiest way to do that is as follows:
1. Get the alpha bitmap using L_GetBitmapAlpha() method.
2. Use L_GetBitmapColorCount() method on the alpha bitmap and check the color count.
3. If the color count is more than one, this means that the image has a transparency.
4. If the color count is only one color, check the first pixel in the alpha bitmap and see if it White or Black.
a) If the first pixel is white, then the image doesn't have transparency.
b) If the first pixel is Black or non white color, then the image has transparency.
Mohamed Abedallah
Developer Support Engineer
LEAD Technologies, Inc.
#5
Posted
:
Thursday, June 6, 2013 6:45:33 AM(UTC)
Groups: Registered
Posts: 12
Thank you for the detailed explanation.
For item 4 when color is 1, to check the first pixel, what is the best and efficient way to do this?
I am thinking of using L_ConvertToDDB() which will return a HBITMAP and scan the pixel of this HBITMAP. Please advice.
#6
Posted
:
Sunday, June 9, 2013 3:21:02 AM(UTC)
Groups: Registered, Tech Support
Posts: 179
You can use L_GetPixelColor() method and pass zero for the Row and Column to get the first pixel color of the Alpha Bitmap. See the following online topic:
http://www.leadtools.com/help/leadtools/v18/main/api/dllref/l_getpixelcolor.htm
Note: The link is valid at the time of posting.
Mohamed Abedallah
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Imaging
Imaging SDK Questions
How to differentiate a 32 bit PNG/BMP file with transparency and without
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.