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

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

How to draw a PNG image in a window?

Help me out with some sample code.

I tried some codes that are available on the Internet, but they all use MFC.

+4
source share
5 answers

Take a look at fooobar.com/questions/733085 / .... It offers several options that should suit 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; } 
+5
source

Your options: GDI +, WIC (Windows image processing component) or libpng

+3
source

You can use GDI +. See Download and display bitmap images .

+2
source

The following code worked for me. It does not contain MFC and can be used immediately 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 your support and quick response to solve my problem.

+1
source

If you know PNG encoding, you can decode it. This way you can draw PNG in any way ~

0
source

All Articles