Load a png resource into a CBitMap(将 png 资源加载到 CBitMap)
问题描述
如何将 png 资源加载到 CBitMap 中?当我尝试这个时,它似乎不起作用:
CImage 图像;image.LoadFromResource(AfxGetInstanceHandle(), IDB_PNG1);bitmap.Attach(image.Detach());它给了我一个找不到资源类型的错误.有没有其他方法可以加载 PNG 资源?
如果您使用的是 VS2008 或更新版本 (MFC Feature Pack),您可以使用从 CBitmapCPngImage> 并包含在 <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());
这篇关于将 png 资源加载到 CBitMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 png 资源加载到 CBitMap
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
