使用GDIPlus显示存储为alpha资源的图标(WIn32 C ++) [英] Displaying Icons stored as resources with alpha using GDIPlus (WIn32 C++)

查看:169
本文介绍了使用GDIPlus显示存储为alpha资源的图标(WIn32 C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要使用GDIPlus显示部分alpha(alpha值介于0到255之间)的图标。当使用采用直接文件名的GDI +的Bitmap构造函数时,文件会正确显示。但是,从资源加载时,它在识别alpha时出现问题。我查看了MSDN,但是alpha存在问题: http:/ /msdn.microsoft.com/en-us/library/windows/desktop/ms536318.aspx 。通过从Icon中检索ICONINFO结构,我可以摆脱完全透明的像素,但是,部分透明像素仍然显示为完全不透明或完全透明。

I have an icon with partial alpha (alpha values between 0 and 255) that I want to display using GDIPlus. When using the Bitmap constructor of GDI+ that takes the direct filename, the file displays properly. However, when loading from resource, it has a problem recognizing alpha. I looked on MSDN, and there are problems with alpha: http://msdn.microsoft.com/en-us/library/windows/desktop/ms536318.aspx. By retrieving the ICONINFO structure from the Icon, I can get rid of the fully transparent pixels, however, the partially transparent pixels still appear either as fully opaque or fully transparent.

我想知道如何使用部分alpha值从资源中的Icon创建Win32位图。

I wanted to know how to create a Win32 Bitmap from an Icon in resource with the partial alpha values.

推荐答案

您可以使用 LoadResource 获取指向图标及其图像数据的指针。您可以将指向图像数据的指针传递给相应的位图构造函数。这是一件苦差事,因为图标有特殊资源格式

You can use LoadResource to get a pointer to the icon and and its image data. You can pass the pointer to the image data to the appropriate Bitmap constructor. This is a bit of a chore because icons have a peculiar resource format.

如果可能,将图像存储为透明(即32bpp argb)位图会更简单。在这种情况下,您可以使用 LoadImage 使用LR_CREATEDIBSECTION。

If possible, it would be simpler to store your image as a transparent (i.e. 32bpp argb) bitmap. In this case you can use LoadImage with LR_CREATEDIBSECTION.

更新

显然LoadIcon确实加载了alpha正确。当你从HICON构造一个GdiPlus :: Bitmap时,问题似乎是GdiPlus不尊重alpha。你能做的是:

Apparently LoadIcon does load the alpha correctly. It would appear that the problem is GdiPlus not respecting the alpha when you construct a GdiPlus::Bitmap from an HICON. What you could do is:


  • 使用LoadIcon加载图标。

  • 使用GetIconInfo获取ICONINFO。 hbmColor是透明位图的句柄。

  • 使用GetDIBits从hbmColor获取位图位。

  • 将数据传递给位图构造函数,需要理解和理解alpha。

  • Use LoadIcon to load the icon.
  • Use GetIconInfo to get the ICONINFO. hbmColor is the handle of the transparent bitmap.
  • Use GetDIBits to get the bitmap bits from hbmColor.
  • Pass the data to the Bitmap constructor that takes bits and understands alpha.

这篇关于使用GDIPlus显示存储为alpha资源的图标(WIn32 C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆