Click here to Skip to main content
13,558,765 members
Click here to Skip to main content
Add your own
alternative version


27 bookmarked
Posted 27 Apr 2004

How to use GDI+ to save image in WMF, EXIF or EMF format

, 27 Apr 2004
Rate this:
Please Sign up or sign in to vote.
An article on GDI+ and how to save image in WMF, EXIF or EMF format.


When I use the Image::Save() function in GDI+ to save an image as BMP, GIF, TIFF, PNG or JPEG, the program works very well. But it fails to do so if I want to save an image as WMF, EXIF or EMF.

The reason of such a case has been well explained in MSDN.

However, I also found that in C#, we could use Image::Save() function to save an image as WMF, EXIF or EMF format, with no pains.

Finally, Feng Yuan helped me out of this problem. Thanks a lot for him.

The solution

Actually, the solution code is quite simple. First, construct a Metafile object and then draw graphics on it. For example, we can have:

Bitmap* m_pBitmap;
// do some paintings on m_pBitmap
CString sFileName = "c:\\1.emf";
// you can use "c:\\1.exi" or "c:\\1.wmf" here,
// and you can also build it as IStream
CDC *cdc = GetDC();
Metafile *metafile = 
         new Metafile(ToWChar(sFileName.GetBuffer(sFileName.GetLength())), 
Graphics graphics(metafile);
graphics.DrawImage(m_pBitmap, 0, 0, m_pBitmap->GetWidth(), 

Then, we can find the resulting image on driver C:. Simple, isn't it? Here, ToWChar() is a simple function to transform a CString object to WCHAR*. It can be written as:

static WCHAR* ToWChar(char * str) 
  // in GDI+, all the parameters about the symbol are WCHAR type
  // this funciton is a tranformation function

  static WCHAR buffer[1024];
  return buffer;


  • Initial release 2004-04-27.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

China China
I am now a faculty in Engineering. But I am also a programmer who use VC from VC1.5 to VC8.0. However, now I prefer to use C# and VB.Net in my job.

You may also be interested in...


Comments and Discussions

GeneralDownload GDI+ version 1.1 Pin
pubba23-May-04 17:47
susspubba23-May-04 17:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180515.1 | Last Updated 28 Apr 2004
Article Copyright 2004 by TeleStar
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid