A metafile represents a set of records, each of which encapsulates a
graphics operation.
There are a large number of different constructors, which allow you
to construct a metafile from a file or stream (in Windows Enhanced
Metafile File format), a system HDC (which can be obtained from a
Graphics surface if necessary), or a Windows EMF
handle. You can subsequently retrieve the EMF handle (for interop)
with the GetHenhmetafile() method. Many of the
methods also allow you to specify a rectangle that positions the
metafile on the page, along with the units that define that rectangle
(see MetafileFrameUnit).
You can retrieve the MetafileHeader with the
GetMetafileHeader() method.
While you can use the System.Drawing.Graphics.DrawImage() method to paint the metafile, you can play an individual
record with the PlayRecord() method. See
EmfPlusRecordType for information about EMF
records.
To record a metafile, you should create a reference
System.Drawing.Graphics surface, and then use the
System.Drawing.Graphics.GetHdc() to lock its
Win32 HDC. You can then pass this as the reference HDC in an
appropriate constructor for your Metafile object.
You can then use the System.Drawing.Graphics.FromImage() method to get a graphics surface for the metafile.
Everything you then draw on the surface will be recorded on the
metafile. If you specified a filename or stream in the
Metafile constructor, the image will automatically
be stored, or you can call the Save() method. You
should then Dispose() the
System.Drawing.Graphics object, the
Metafile, and call
System.Drawing.Graphics.ReleaseHdc().
public sealed class Metafile : System.Drawing.Image {
// Public Constructors
public Metafile(IntPtr henhmetafile, bool deleteEmf);
public Metafile(IntPtr referenceHdc, EmfType emfType);
public Metafile(IntPtr referenceHdc, EmfType emfType, string description);
public Metafile(IntPtr referenceHdc, System.Drawing.Rectangle frameRect);
public Metafile(IntPtr referenceHdc, System.Drawing.RectangleF frameRect);
public Metafile(IntPtr referenceHdc, System.Drawing.RectangleF frameRect, MetafileFrameUnit frameUnit);
public Metafile(IntPtr referenceHdc, System.Drawing.RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type);
public Metafile(IntPtr referenceHdc, System.Drawing.RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type,
string description);
public Metafile(IntPtr referenceHdc, System.Drawing.Rectangle frameRect, MetafileFrameUnit frameUnit);
public Metafile(IntPtr referenceHdc, System.Drawing.Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type);
public Metafile(IntPtr referenceHdc, System.Drawing.Rectangle frameRect, MetafileFrameUnit frameUnit, EmfType type,
string desc);
public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader);
public Metafile(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader, bool deleteWmf);
public Metafile(System.IO.Stream stream);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, EmfType type);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, EmfType type, string description);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, System.Drawing.Rectangle frameRect);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, System.Drawing.RectangleF frameRect);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, System.Drawing.RectangleF frameRect,
MetafileFrameUnit frameUnit);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, System.Drawing.RectangleF frameRect,
MetafileFrameUnit frameUnit, EmfType type);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, System.Drawing.RectangleF frameRect,
MetafileFrameUnit frameUnit, EmfType type, string description);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, System.Drawing.Rectangle frameRect,
MetafileFrameUnit frameUnit);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, System.Drawing.Rectangle frameRect,
MetafileFrameUnit frameUnit, EmfType type);
public Metafile(System.IO.Stream stream, IntPtr referenceHdc, System.Drawing.Rectangle frameRect,
MetafileFrameUnit frameUnit, EmfType type, string description);
public Metafile(string filename);
public Metafile(string fileName, IntPtr referenceHdc);
public Metafile(string fileName, IntPtr referenceHdc, EmfType type);
public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string description);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.Rectangle frameRect);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.RectangleF frameRect);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.RectangleF frameRect,
MetafileFrameUnit frameUnit);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.RectangleF frameRect,
MetafileFrameUnit frameUnit, EmfType type);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.RectangleF frameRect,
MetafileFrameUnit frameUnit, EmfType type, string description);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.RectangleF frameRect,
MetafileFrameUnit frameUnit, string desc);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.Rectangle frameRect,
MetafileFrameUnit frameUnit);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.Rectangle frameRect,
MetafileFrameUnit frameUnit, EmfType type);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.Rectangle frameRect,
MetafileFrameUnit frameUnit, EmfType type, string description);
public Metafile(string fileName, IntPtr referenceHdc, System.Drawing.Rectangle frameRect,
MetafileFrameUnit frameUnit, string description);
// Public Static Methods
public static MetafileHeader GetMetafileHeader(IntPtr henhmetafile);
public static MetafileHeader GetMetafileHeader(IntPtr hmetafile, WmfPlaceableFileHeader wmfHeader);
public static MetafileHeader GetMetafileHeader(System.IO.Stream stream);
public static MetafileHeader GetMetafileHeader(string fileName);
// Public Instance Methods
public IntPtr GetHenhmetafile();
public MetafileHeader GetMetafileHeader();
public void PlayRecord(EmfPlusRecordType recordType, int flags, int dataSize, byte[ ] data);
}