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

天涯浪子 提交于 2019-12-06 01:00:21

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.

I wrote a blog post (on displaying a splash screen with C++) that contains a full code sample that loads a PNG from a resource and converts it to an HBITMAP (using WIC). You could then use CreateCompatibleDC, SelectObject, and BitBlt to display it in the target HDC.

While I haven't ever tried it, you should be able to use StretchDIBits to display the PNG directly if you load the raw bytes from the resource into memory, and set up a BITMAPINFOHEADER struct with the width, height, etc. as demonstrated in this MSDN sample.

C# and VB.NET solutions would be quite different because you could use System.Drawing (a wrapper for GDI+) or System.Windows.Media.Imaging (in a WPF app) to handle the image loading and drawing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!