0

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?

Andreas
  • 9,245
  • 9
  • 49
  • 97
  • IWICPixelFormatInfo2::SupportsTransparency? https://learn.microsoft.com/en-us/windows/win32/api/wincodec/nf-wincodec-iwicpixelformatinfo2-supportstransparency – Simon Mourier Nov 01 '20 at 14:48
  • @SimonMourier: Yes, that does the job. Thanks a lot! If you want to post this as an official answer, I'll accept it. – Andreas Nov 02 '20 at 15:39

1 Answers1

1

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

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298