Click here to Skip to main content
15,996,446 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have picture control on my startpage in visual studio. I have also a picture png in my resource.
But it is a problem to load it. Is it possible or we can only load bitmap?

What I have tried:

I wanted to load a picture from properties. But as it is not bmp, my file png it is not visible.

I tried also
m_pictureLogo.SetBitmap(MTOFileSystem::loadImage(Global::getPhotosDir() + "\\" + L"IDB_BITMAP_LOGO_NEW.png"));

but it does not work too.....

What to do?
Posted
Updated 5-Dec-17 0:08am

You might use the CPngImage Class[^] from the MFC Feature pack:
C++
#include <afxtoolbarimages.h>

CPngImage image;
image.Load(IDB_BITMAP_LOGO_NEW, AfxGetInstanceHandle());
// EDIT: Must cast here
//m_pictureLogo.SetBitmap(image.Detach());
m_pictureLogo.SetBitmap((HBITMAP)image.Detach());
 
Share this answer
 
v2
Comments
Member 13495762 6-Dec-17 3:42am    
Hi, it seems good. where should I put last two lines in cpp file?
image.Load(IDB_BITMAP_LOGO_NEW, AfxGetInstanceHandle());
m_pictureLogo.SetBitmap(image.Detach());
I put it in DoDataExchange, In last line of code there is an error
m_pictureLogo.SetBitmap(image.Detach()); ->argument of type "HGIOBJ" is incompatible wit parameter of type "HBITMAP" ....
Jochen Arndt 6-Dec-17 4:12am    
Just cast the return value (I will update my solution):
m_pictureLogo.SetBitmap((HBITMAP)image.Detach());

I would place the code in the Init function of the parent window (CDialog: OnInitDialog, CView: OnInitialUpdate).
Member 13495762 6-Dec-17 4:20am    
Thanks , I will try and let You know. I need png files to add becasue I need transparency
Jochen Arndt 6-Dec-17 4:31am    
But you do know that the PNG is converted to a bitmap which is then shown by the control and the CStatic picture control does not support transparency?

Member 13495762 6-Dec-17 4:36am    
I see...so it will not help me. I need to load png files (which have transperency) to my picture control boxes on our startpage instead of bmp file...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900