Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
413 views
Welcome To Ask or Share your Answers For Others

1 Answer

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());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...