windowswinapiwic

How to check if image has an alpha channel


I'm loading an image using the Windows Imaging Component. I can easily find out the pixel format of the image by calling IWICBitmapSource::GetPixelFormat(). I can also easily find out the number of bits per pixel and the number of channels by using the IWICPixelFormatInfo interface.

But how can I find out if one of the channels is an alpha channel? Of course, I could go ahead and manually compare the WICPixelFormatGUID obtained from IWICBitmapSource::GetPixelFormat() against MSDN's list of WIC image formats but this is a very inconvenient way because there are dozens of different formats I'd have to compare it against and it's also not very future-proof in case more formats are added in the future.

So is there a better way to tell if one of the image's channels is an alpha channel?


Solution

  • You can use the IWICPixelFormatInfo2::SupportsTransparency method. Note this interface may not be always supported though.