Discussion:
Loading PNG from C++ (MFC) in Windows CE
(too old to reply)
eric
2009-01-12 14:13:05 UTC
Permalink
How can we do that?
How to load a PNG file into a HBITMAP?

thx,
eric.
Christopher Fairbairn [MVP]
2009-01-12 21:01:39 UTC
Permalink
Hi,
Post by eric
How can we do that?
How to load a PNG file into a HBITMAP?
Depending upon platform and usage requirements one option that comes to mind
is SHLoadImageFile (an API documented on MSDN at
http://msdn.microsoft.com/en-us/library/aa455003.aspx). Its usage is fairly
straight forward:

HBITMAP hbmp = SHLoadImageFile(L"\path\to\some.png");

However the API is limited if you want to deal with transparency and alpha
blending etc. In that case on a Windows Mobile 5.0 or higher device you may
like to investigate the COM based Imaging API
(http://msdn.microsoft.com/en-us/library/ms879887.aspx).

I have a code snippet / sample application demonstarting the use of this API
available on my blog at http://www.christec.co.nz/blog/archives/361

Hope this helps,
Christopher Fairbairn
eric
2009-01-13 08:15:22 UTC
Permalink
Christopher,

that is exactly what we need!
Thanks a lot for that informations.

eric.
eric
2009-01-13 09:21:57 UTC
Permalink
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
IImagingFactory *pFactory = NULL;
hr = CoCreateInstance(CLSID_ImagingFactory, NULL,
CLSCTX_INPROC_SERVER, /*IID_IImagingFactory*/ __uuidof
(IImagingFactory) , (void**)&pFactory);

if (hr == S_OK)
{
IImage *pImage = NULL;
hr = pFactory->CreateImageFromFile(L"\\ThePath\\TheImage.png",
&pImage);
if (hr == S_OK)
{
CDC *pCdc = GetDC();
RECT rect;
rect.top = 0;
rect.left = 0;
rect.bottom = 200;
rect.right = 200;
hr = pImage->Draw(pCdc->m_hDC, &rect, NULL);

pImage->Release();
pImage = NULL;
ReleaseDC(pCdc);
}

pFactory->Release();
pFactory = NULL;
}


eric.

Continue reading on narkive:
Loading...