Search code examples
c++imagepnggdistretchdibits

How would I draw a PNG image using LoadImage and StretchDIBits?


(This is related to the question on How would I load a PNG image using Win32/GDI (no GDI+ if possible)?.)

Hi all,

I was wondering, given that you have a PNG resource embedded in a binary file with the ID IDB_PNG1, and an LPDRAWITEMSTRUCT to draw into (so that means you have the HDC and the rectangle for your target), how do you draw that image onto the screen using StretchDIBits? I've worked with BitBlt and TransparentBlt before, but StretchDIBits seems to work differently, and LoadImage doesn't seem to work with PNG's.

Thank you!

(Note: The language I put is C++, but that's not too important... C, C#, Visual Basic, etc. would be fine; I'm just trying to figure out the steps, not the exact code needed.)


Solution

  • I think the PNG support inside bitmaps is only really for use by printer drivers. For screen display, you will probably have to decompress the PNG data yourself using some code such as libpng.