Welcome to LEAD Support Forum Login | Register | Faq  

    LEAD Support Forum
  Resource to find answers and post technical questions about LEAD products.
Search    
   

How do I detect if a bitmap has an alpha channel
Started by damiandixon at 06-18-2008 11:18. Topic has 3 replies.

Print Search « Previous Thread Next Thread »
  06-18-2008, 11:18
damiandixon is not online. Last active: 8/11/2008 11:19:25 AM damiandixon

Not Ranked
Joined on 06-18-2008
Posts 4
How do I detect if a bitmap has an alpha channel
Reply Quote
I have a number of bitmap's some with alpha channels some with no alpha channel.

I would like to detect if an alpha channel exists so that I do not do any unnecessary work.

Currently I use the following code:

      LBitmap alpha;
      if (alpha.CreateAlphaBitmap(*m_bitmap) == SUCCESS)
      {
        // yes so set a region based on this.
        if (alpha.GetBitsPerPixel() != 1)
        {
          alpha.ColorRes(1, CRF_FIXEDPALETTE | CRF_NODITHERING );
        }
        m_bitmap->Region()->SetRgnFromMask(alpha);
        // see if bitmap has a useable region if not then free it
        L_UINT32 area;
        m_bitmap->Region()->GetRgnArea(&area);
        if (area == 0)
        {
          m_bitmap->Region()->Free();
        }
      }
So at this point if I have no region then I did not have an alpha channel...

I am using leadtools 14.5.

Thanks Damian

   Report 
  06-18-2008, 14:21
GregR is not online. Last active: 11/17/2008 11:10:19 AM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,706
Re: How do I detect if a bitmap has an alpha channel
Reply Quote
Does the code you have currently work for you or are you just looking for an alternative?

Are you wanting to determine this before you load the image or after the image has been loaded? 

You can determine this before loading the image by using LFile::GetInfo.  Then check to see if the FILEINFO_HAS_ALPHA flag is set in the FILEINFO.Flags property.

Greg Ross
LEADTOOLS Technical Support
   Report 
  06-20-2008, 3:11
damiandixon is not online. Last active: 8/11/2008 11:19:25 AM damiandixon

Not Ranked
Joined on 06-18-2008
Posts 4
Re: How do I detect if a bitmap has an alpha channel
Reply Quote
I wish to determine if the image has an alpha channel after it has been loaded but before processing.

I wish to avoid creating a region if at all possible.

I have found that an image with no alpha channel creates an alpha bitmap.

I wish to avoid creating an alpha bitmap if no alpha exists.

Does the FILEINFO_HAS_ALPHA flag differentiate between a file with an alpha channel and one with just a transparent colour (PNG transparent colour)?

Thanks
Damian



   Report 
  06-23-2008, 9:13
GregR is not online. Last active: 11/17/2008 11:10:19 AM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,706
Re: How do I detect if a bitmap has an alpha channel
Reply Quote
If you don't want to make a separate call to L_FileInfo, you can pass a new pFILEINFO directly into L_LoadBitmap and it will update it just as if you called L_FileInfo separately.  For more details on different uses of the FILEINFO struct in L_LoadBitmap, please see the documentation article for L_LoadBitmap.

FILEINFO_HAS_ALPHA only detects alpha channels, not transparent colors as in a PNG with single transparent color or GIFs.  If you want to detect a single transparent color, this will be found in the BITMAPHANDLE.Transparency and BITMAPHANDLE.Flags.Transparency properties.

Greg Ross
LEADTOOLS Technical Support
   Report 
Post
LEAD Support Fo... » Developer » Image Processin... » How do I detect if a bitmap has an alpha channel

Powered by Community Server, by Telligent Systems