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),您可以使用从 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());
这篇关于将 png 资源加载到 CBitMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 png 资源加载到 CBitMap


基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09