Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I am facing a problem.I have to load images in any format and display them as contact photo of users,where in this function OleLoadPicturePath() doesn't accept .png images. My basic need is to attach a PNG image to a imagelist which is used to load that image.Since Im not using CImage,best way which I got from browsing is to Convert that PNG to a Bitmap and attach this to the imagelist.Can anyone please tell me how I can go ahead with this??Thanks in advance.
Posted
Updated 3-Nov-19 13:43pm

What would you probably do?

If this way is bad :

CImage image;
image.Load(_T("C:\\myimage.png"));
CBitmap bitmap;
bitmap.Attach(image.Detach());

So, try following way:
An MFC picture control to dynamically show pictures in a dialog[^]


Regards,
Alex.
 
Share this answer
 
Show some code or what is the error? Compressed png arent supported, so you need something else.

I recommand this article for image issues:
http://www.codeproject.com/Articles/1300/CxImage
 
Share this answer
 
Load the PNG with CreateIconFromResourceEx then add that icon to your imagelist.

HICON LoadIconPNG(LPCTSTR lpFileName, INT nWidth, INT nHeight)
{
	HICON	hIcon = NULL;
	HANDLE	hFile;
	DWORD	dwsz, dwbr;
	BYTE	*pb;
	if ((hFile = CreateFile(lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) return (NULL);
	dwsz = GetFileSize(hFile, NULL);
	pb = (BYTE *) malloc(sizeof(BYTE) * dwsz);
	if (!ReadFile(hFile, pb, dwsz, &dwbr, NULL)) { free(pb); CloseHandle(hFile); return (NULL); }
	CloseHandle(hFile);
	hIcon = CreateIconFromResourceEx(pb, dwsz, TRUE, 0x00030000, 0, 0, LR_DEFAULTCOLOR);	
	free(pb);
	return (hIcon);
}
 
Share this answer
 
Comments
Stefan_Lang 7-Nov-19 2:45am    
I doubt the OP will still be interested in a solution after 7.5 years! Please check the date of the question before issuing a solution.
jongman 17-Sep-20 18:10pm    
Well, at least it was useful for me.

Thanks emilynx!

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