将位图转换为图元文件 (.emf)
我有一个位图(.bmp)文件,我想将其转换为图元文件(.emf)格式。目前我正在使用这段代码:
Metafile metafile;
using (MemoryStream stream = 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
);
为什么这段代码不能正常工作?请向我提供将位图文件转换为图元文件(特别是 .emf)文件的完整代码。 或者 如果可能的话请告诉我如何以图元文件格式保存图形对象。 假设我现在有了这段代码,
Graphics NewGraphicsObj = m_ActiveTab.Controls[0].CreateGraphics();
我想将这个 NewGraphicsObj 保存到图元文件中。
任何人对这个主题有帮助,
提前致谢...
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 = 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论