Metafiles in GDI+

GDI+ provides the Metafile class so that you can record and display metafiles. A metafile, also called a vector image, is an image that is stored as a sequence of drawing commands and settings. The commands and settings recorded in a Metafile object can be stored in memory or saved to a file or stream.

Metafile Formats

GDI+ can display metafiles that have been stored in the following formats:

  • Windows Metafile (WMF)

  • Enhanced Metafile (EMF)

  • EMF+

GDI+ can record metafiles in the EMF and EMF+ formats, but not in the WMF format.

EMF+ is an extension to EMF that allows GDI+ records to be stored. There are two variations on the EMF+ format: EMF+ Only and EMF+ Dual. EMF+ Only metafiles contain only GDI+ records. Such metafiles can be displayed by GDI+ but not by GDI. EMF+ Dual metafiles contain GDI+ and GDI records. Each GDI+ record in an EMF+ Dual metafile is paired with an alternate GDI record. Such metafiles can be displayed by GDI+ or by GDI.

The following example displays a metafile that was previously saved as a file. The metafile is displayed with its upper-left corner at (100, 100).

public void Example_DisplayMetafile(PaintEventArgs e)
{
    Graphics myGraphics = e.Graphics;
    Metafile myMetafile = new Metafile("SampleMetafile.emf");
    myGraphics.DrawImage(myMetafile, 100, 100);
}
Public Sub Example_DisplayMetafile(ByVal e As PaintEventArgs)
    Dim myGraphics As Graphics = e.Graphics
    Dim myMetafile As New Metafile("SampleMetafile.emf")
    myGraphics.DrawImage(myMetafile, 100, 100)
End Sub

See also