Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to draw a PNG image on window without using MFC?

Tags:

image

png

winapi

I am developing a Windows API application without using MFC. I am using standard Windows libraries.

How do I draw a PNG image in a window?

Help me with some sample code.

I have tried some codes which are available on the Internet, but all are using MFC.

like image 804
Vinayaka Karjigi Avatar asked Dec 15 '09 06:12

Vinayaka Karjigi


2 Answers

Take a look at this StackOverflow question. It offers several options which should meet your needs.

Adapted from 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;
}
like image 131
Justin Grant Avatar answered Nov 18 '22 18:11

Justin Grant


Your choices are: GDI+, WIC(Windows Imaging Component) or libpng

like image 3
Anders Avatar answered Nov 18 '22 18:11

Anders