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.
Actually, the solution code is quite simple. First, construct a Metafile object and then draw graphics on it. For example, we can have:
CString sFileName = "c:\\1.emf";
CDC *cdc = GetDC();
Metafile *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)
static WCHAR buffer;
- Initial release 2004-04-27.
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.