Re: simple requirement related to displaying jpegs
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:ddcar3tqvg90s47daa5nrkhfdpnlb8ld25@4ax.com...
There is apparently no JPEG-from-resource conversion mechanism; I'd
probably investigate
the JPEG libraries in places like www.codeproject.com
GDI+ offers this, e.g. Image::FromStream(). Paul di Lascia's CPicture
class, based on GDI+ (available in MSDN magazine) does this:
BOOL CPicture::Load(IStream* pstm)
{
DestroyPicture();
m_pImage = Image::FromStream(pstm, m_bUseEmbeddedColorManagement);
return m_pImage->GetLastStatus()==Ok;
}
BOOL CPicture::LoadFromMem(HGLOBAL hMem)
{
IStream* pstm;
VERIFY(CreateStreamOnHGlobal(hMem,FALSE,&pstm)==S_OK);
BOOL bRet = Load(pstm); // load from stream
GlobalUnlock(hMem);
pstm->Release();
m_hMem = hMem;
return bRet;
}
//////////////////
// Load from resource. Looks for "IMAGE" type.
//
BOOL CPicture::Load(UINT nIDRes)
{
DestroyPicture();
if (nIDRes==0)
return FALSE;
// find resource in resource file
HINSTANCE hInst = AfxGetResourceHandle();
HRSRC hRsrc = ::FindResource(hInst,
MAKEINTRESOURCE(nIDRes),
_T("IMAGE")); // type
if (!hRsrc)
return FALSE;
// load resource into memory
DWORD len = SizeofResource(hInst, hRsrc);
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
if (!lpRsrc)
return FALSE;
// create stream on global memory
HGLOBAL hMem = GlobalAlloc(GMEM_FIXED, len);
BYTE* buf = (BYTE*)GlobalLock(hMem);
memcpy(buf, lpRsrc, len);
FreeResource(lpRsrc);
return LoadFromMem(hMem);
}
-- David