将 png 资源加载到 CBitMap
如何将 png 资源加载到 CBitMap
中?当我尝试这个时,它似乎不起作用:
CImage 图像;image.LoadFromResource(AfxGetInstanceHandle(), IDB_PNG1);bitmap.Attach(image.Detach());
它给了我一个找不到资源类型的错误.有没有其他方法可以加载 PNG 资源?
解决方案如果您使用的是 VS2008 或更新版本 (MFC Feature Pack),您可以使用从 CBitmap
CPngImage> 并包含在 <afxtoolbarimages.h>
中.CPngImage
是一个 内部类:
以下类在 MFC 内部使用.为了完整起见,本节描述了这些内部类,但它们并不打算直接在您的代码中使用.
如果要使用CPngImage
需要使用资源类型"PNG"
:
#define AFX_PNG_RESOURCE_TYPE _T("PNG")
示例用法
CPngImage 图像;image.Load(IDB_PNG1, nullptr);bitmap.Attach(image.Detach());
How do I load a png resource into a CBitMap
? When I try this it doesn't seem to work:
CImage image;
image.LoadFromResource(AfxGetInstanceHandle(), IDB_PNG1);
bitmap.Attach(image.Detach());
It gives me an error resource type not found. Is there any other way to load a PNG resource?
解决方案If you are using VS2008 or newer (MFC Feature Pack) you can use CPngImage
which derives from CBitmap
and is contained in <afxtoolbarimages.h>
. CPngImage
is an internal class:
The following classes are used internally in MFC. For completeness, this section describes these internal classes, but they are not intended to be used directly in your code.
If you want to use CPngImage
you need to use the resource type "PNG"
:
#define AFX_PNG_RESOURCE_TYPE _T("PNG")
Example usage
CPngImage image;
image.Load(IDB_PNG1, nullptr);
bitmap.Attach(image.Detach());
相关文章