Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, June 18, 2008 6:18:54 AM(UTC)
damiandixon

Groups: Registered
Posts: 5


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
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, June 18, 2008 9:21:36 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 766


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.
 
#3 Posted : Thursday, June 19, 2008 10:11:56 PM(UTC)
damiandixon

Groups: Registered
Posts: 5


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


 
#4 Posted : Monday, June 23, 2008 4:13:24 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 766


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.
 
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.

Powered by YAF.NET | YAF.NET © 2003-2020, Yet Another Forum.NET
This page was generated in 0.203 seconds.