HBITMAP 可以包含 alpha 通道信息吗?

Can a HBITMAP contains alpha channel information?

我注意到 ICONINFO 包含两个位图。如果我理解正确的话,hbmMask 是图标的轮廓,同时指定哪个部分应该是透明的,hbmColor 是图标的实际颜色 HBITMAP

所以我的问题是,为什么 hbmMask 是必要的?为什么不直接将 alpha 通道的信息放在 hbmColor 中?是否可以将它们组合成一个位图?

此外,Gdiplus::Bitmap 有一个 constructor which accepts a HICON 。这是否意味着此 GDI+ 位图能够处理 alpha 通道信息?

谢谢:)

why the hbmMask is necessary? Why not just put the alpha channel's information inside hbmColor?

Alpha 通道仅适用于 32 bpp 位图(8 位 Alpha 通道,各 8 位红色、绿色和蓝色通道)。因此,具有 1 到 8 bpp 位图的图标必须将透明度信息与颜色位图分开存储在 hbmMask 位图中。

实际上,即使是具有 alpha 通道的 32 bpp 位图,are required to include the hbmMask, unless the PNG format is used。在后一种情况下,遮罩自动从 alpha 通道导出。

Besides, Gdiplus::Bitmap has a constructor which accepts a HICON . Does it mean this GDI+ bitmap is able to handle alpha channel information?

由于文档没有另外说明,您可以安全地假设构造函数将 32 bpp HICON 转换为 32 bpp 位图。如果像素格式合适,GDI+ 位图当然能够存储 alpha 通道(在图标的情况下需要 PixelFormat32bppARGB)。