I tried the following code on OnInitDialog() but nothing was shown.
m_staticLogo.SetBitmap(::LoadBitmap(NULL, MAKEINTRESOURCE(IDB_LOGO)));
where m_staticLogo is the static picture control and IDB_LOGO is the resource ID of the png file.
I tried the following code on OnInitDialog() but nothing was shown.
m_staticLogo.SetBitmap(::LoadBitmap(NULL, MAKEINTRESOURCE(IDB_LOGO)));
where m_staticLogo is the static picture control and IDB_LOGO is the resource ID of the png file.
For those, who need quick solution, here is a way to load png file from resources using GDI+ (original answer for standard GDI from here - http://www.codeproject.com/Questions/377803/How-to-load-PNG-images-in-mfc):
You can add png file as resource using Add Resource command and in the panel choose Import.
Bitmap and icon it supports. Not sure about png. Alternately, May be you can try the following.
If you are converting .png image file to .bmp format, you can end up with image clarity. So, catch WM_PAINT message in dialog box class and use
Graphics::DrawImage method
To obtain this method link your project with gdiplus.lib library.
As you’ve discovered,
::LoadBitmap
(and the newer::LoadImage
) only deal with.bmp
s. By far the easiest solution is to convert your image to a.bmp
.If the image has transparency, it can be converted into a 32-bit ARGB bitmap (here is a tool called AlphaConv that can convert it). Then load the image using the
CImage
classLoadFromResource
method. Pass theCImage
tom_staticLogo.SetBitmap()
.But if you really need it to be a
.png
, it can be done.Method 1 (the easier way): Load the
.png
from a file usingCImage::Load
. Pass theCImage
tom_staticLogo.SetBitmap()
.Method 2 (the harder way): Load the
.png
from a resource by loading the resource into a COMIStream
and usingCImage::Load
. (NOTE:CImage::LoadFromResource
looks tempting but will not work with a.png
graphic). To get the resource into a COMIStream
, see this Codeproject article. Note the article works withGdiplus::Bitmap
but the key part is how to create theIStream
, which you should be able to adapt forCImage
. Finally, pass theCImage
tom_staticLogo.SetBitmap()
.Edit: Updated to use
CImage
, which is easier thanGdiplus::Bitmap
.