I have a bitmap(.bmp) file and I want to convert it into metafile(.emf) format. Currently I am using this code:
Metafile metafile;
using (MemoryStream stream开发者_Python百科 = new MemoryStream())
using (Graphics rtfBoxGraphics = m_ActiveTab.Controls[0].CreateGraphics())
{
IntPtr pDeviceContext = rtfBoxGraphics.GetHdc();
metafile = new Metafile(stream, pDeviceContext);
using (Graphics imageGraphics = Graphics.FromImage(metafile))
{
imageGraphics.DrawImageUnscaled(bmp1, new Rectangle(0, 0,bmp1.Width, bmp1.Height));
}
rtfBoxGraphics.ReleaseHdc(pDeviceContext);
}
// Get a handle to the metafile
IntPtr iptrMetafileHandle = metafile.GetHenhmetafile();
// Export metafile to an image file
CopyEnhMetaFile(iptrMetafileHandle, @"e:\Test\test4.emf");
// Delete the metafile from memory
DeleteEnhMetaFile(iptrMetafileHandle);
[DllImport("gdi32.dll")]
static extern IntPtr CopyEnhMetaFile( // Copy EMF to file
IntPtr hemfSrc, // Handle to EMF
String lpszFile // File
);
[DllImport("gdi32.dll")]
static extern int DeleteEnhMetaFile( // Delete EMF
IntPtr hemf // Handle to EMF
);
Why is this code not work properly? Please provide me full code to convert a bitmap file to metafile(specially .emf) file. or If possible then tell me how can I save a graphics object in metafile format. Suppose I have this code
Graphics NewGraphicsObj = m_ActiveTab.Controls[0].CreateGraphics();
now I want to save this NewGraphicsObj
into a metafile.
Any one help on this topic
Thanks in advance...
精彩评论