DisplayBMP/JPEG/JPG/PNG/GIF/TIFF/ Exif/WMF/EMF (from file) in VC++ using GDI+

/*
NOTE:
=====

Add this block of code in “InitInstance” of your project.

//begin: initialize GDI+ ////////////////////////////////////////////////////////////
extern ULONG_PTR gdiplusToken; //
GdiplusStartupInput gdiplusStartupInput; //
VERIFY(GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL ) == Ok ); //
//end: initialize GDI+ ////////////////////////////////////////////////////////////

Add this block of code in “ExitInstance” of your project.

//begin: shutdown GDI+ //////////////////////////////
extern ULONG_PTR gdiplusToken; //
GdiplusShutdown(gdiplusToken); //
//end: shutdown GDI+ //////////////////////////////

*/

#include “gdiplus.h”
#pragma comment(lib, “gdiplus.lib”)
using namespace Gdiplus;

CString sPath = _T(“C:\\Bmp\\1.bmp”);
Graphics graphics(pDC->m_hDC);// hdc);
{
WCHAR lpwszData[1024];//Wide char string
DWORD dwSize = sizeof(lpwszData);

#ifndef UNICODE
MultiByteToWideChar(CP_ACP, 0, LPCTSTR(sPath), -1, lpwszData, dwSize);
#else
wcscpy_s(lpwszData, 1024, sPath);
#endif
// Create an Image object.
Image image(lpwszData);

// Draw the image.
graphics.DrawImage(ℑ, Rect(x, y, width, height));
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: