tags:

views:

147

answers:

5

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.

+2  A: 

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;
}
Justin Grant
+2  A: 

You can use GDI+. See Loading and Displaying Bitmaps.

Sergius
+2  A: 

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

Anders
+1  A: 

The below code worked for me. It's free of MFC and can be used straight away to draw PNG images in a window.

    Gdiplus::Image image(L"C:\\Logo.png") ;

    Gdiplus::Graphics* graphics = Gdiplus::Graphics::FromHDC(GetDC(hWnd));

    RectF ImgRect(0,0,y3/10,y3/10) ;

    Gdiplus::Status result = graphics->DrawImage(&image, ImgRect);

Thanks for all your support and quick response to solve my problem.

Vinayaka Karjigi
A: 

If you know PNG'coding,you can decoding it. So you can draw PNG in any way~

Smart_Joe