Convert PNG file to Bitmap without a DC?
I'd like to store images resources as PNGs due to the compression over
bitmps. To load such a resource and get it converted to a bitmap for the
eventual Blit to my screen DC, I basically want the equivalent of
LoadBitmap. Better yet, I was thinking I would create a CBitmap derived
class "CPNGImage" that would have a "LoadPNGResource" method much like
CBitmap's LoadBitmap method. So far so good.
The stumbling block for me at this point is that the process of converting
the PNG to a bitmap seems to require a DC compatible with my device. This
is neatly encapsulated/shown in CxImage's MakeBitmap function:
HBITMAP CxImage::MakeBitmap(HDC hdc)
{
if ((!hdc) || (!hDib)) return NULL;
HBITMAP bmp = CreateDIBitmap(hdc, (LPBITMAPINFOHEADER)hDib, CBM_INIT,
GetBits(), (LPBITMAPINFO)hDib, DIB_RGB_COLORS);
return bmp;
}
Contrast this to LoadBitmap, which does not require an HDC, but will still
load a bitmap (16 or 24 bit color depth) from a resource and seems to
convert it to a 32bit color depth just like what BitBlt to my screen DC
wants. How does LoadBitmap do this without access to my screen DC? Or
rather, how can I accomplish this same thing for my PNG resource without a
screen DC? Or is this not possible?
I have a feeling the answer has something to do with DIB vs. DDB, etc., but
I just can't seem to figure out what is going on here.
Thanks for any help you can offer.
- Wil