有没有办法在不使用MFC的情况下在窗口上绘制PNG图像?

Vin*_*igi 5 winapi png image

我正在开发一个不使用MFCWindows API应用程序.我正在使用标准的Windows库.

如何在窗口中绘制PNG图像?

帮我一些示例代码.

我尝试过一些可在互联网上获得的代码,但都使用的是MFC.

Jus*_*ant 6

看看这个StackOverflow问题.它提供了几个可满足您需求的选项.

改编自MSDN:

#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

void draw()
{
   // start up GDI+ -- only need to do this once per process at startup
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR gdiplusToken;
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);


   Rect rect(20,20,50,50);
   Graphics grpx(dc);
   Image* image = new Image(L"SomePhoto.png");
   grpx.DrawImage(Img,rect);

   delete image;

   // shut down - only once per process
   GdiplusShutdown(gdiplusToken);
   return;
}
Run Code Online (Sandbox Code Playgroud)