http://msdn.microsoft.com/en-us/library/system.drawing.imaging.metafile.aspx”rel=“noreferer”>here:
When you use the Save method to save a
graphic image as a Windows Metafile
Format (WMF) or Enhanced Metafile
Format (EMF) file, the resulting file
is saved as a Portable Network
Graphics (PNG) file instead. This
behavior occurs because the GDI+
component of the .NET Framework does
not have an encoder that you can use
to save files as .wmf or .emf files.
但是,我猜想你已经走了这么远:
Here 某人正在一个文件Stream上绘制一份比图。
metafileStream = MakeMetafileStream(gdiBitmap);
与马克·马塔索姆(MakMetafileStream)合著:
private static MemoryStream MakeMetafileStream(Bitmap image)
{
Graphics graphics = null;
Metafile metafile= null;
var stream = new MemoryStream();
try
{
using (graphics = Graphics.FromImage(image))
{
var hdc = graphics.GetHdc();
metafile= new Metafile(stream, hdc);
graphics.ReleaseHdc(hdc);
}
using (graphics = Graphics.FromImage(metafile))
{ graphics.DrawImage(image, 0, 0); }
}
finally
{
if (graphics != null)
{ graphics.Dispose(); }
if (metafile!= null)
{ metafile.Dispose(); }
}
return stream;
}
Interesting stuff.
But as to the encoder thing...
http://www.ureader.com/msg/1435247.aspx”rel=“noreferer”>Here Peter Huang从MS中张贴了这一未经管理的方法:
[DllImport("gdiplus.dll")]
private static extern uint GdipEmfToWmfBits (IntPtr _hEmf, uint _bufferSize,
byte[] _buffer, int _mappingMode, EmfToWmfBitsFlags _flags);
[DllImport("gdi32.dll")]
private static extern IntPtr SetMetaFileBitsEx (uint _bufferSize,
byte[] _buffer);
[DllImport("gdi32.dll")]
private static extern IntPtr CopyMetaFile (IntPtr hWmf,
string filename);
[DllImport("gdi32.dll")]
private static extern bool DeleteMetaFile (IntPtr hWmf);
[DllImport("gdi32.dll")]
private static extern bool DeleteEnhMetaFile (IntPtr hEmf);
private void button4_Click(object sender, System.EventArgs e)
{
Graphics g= this.CreateGraphics();
IntPtr hDC = g.GetHdc();
Metafile mf = new Metafile(hDC,EmfType.EmfOnly);
g.ReleaseHdc(hDC);
g.Dispose();
g=Graphics.FromImage(mf);
//Pen p = new Pen(Color.White,5);
g.DrawArc(Pens.Black,0,0,200,200,0,360);
//g.DrawImage(Bitmap.FromFile(@"c: emp est.bmp"),0,0);
g.Dispose();
IntPtr _hEmf= mf.GetHenhmetafile();
uint _bufferSize = GdipEmfToWmfBits(_hEmf, 0, null, MM_ANISOTROPIC,
EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault);
byte[] _buffer = new byte[_bufferSize];
GdipEmfToWmfBits(_hEmf, _bufferSize, _buffer, MM_ANISOTROPIC,
EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault);
IntPtr hmf = SetMetaFileBitsEx(_bufferSize, _buffer);
CopyMetaFile(hmf, "C:\ConvertedMetafile.wmf");
DeleteMetaFile(hmf);
DeleteEnhMetaFile(_hEmf);
}
希望你: