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")
CPngImage image;
image.Load(IDB_PNG1, nullptr);
bitmap.Attach(image.Detach());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With