How to: Load and Display Metafiles

The Metafile class, which inherits from the Image class, provides methods for recording, displaying, and examining vector images.


To display a vector image (metafile) on the screen, you need a Metafile object and a Graphics object. Pass the name of a file (or a stream) to a Metafile constructor. After you have created a Metafile object, pass that Metafile object to the DrawImage method of a Graphics object.

The example creates a Metafile object from an EMF (enhanced metafile) file and then draws the image with its upper-left corner at (60, 10).

The following illustration shows the metafile drawn at the specified location.

Image Position

Metafile metafile = new Metafile("SampleMetafile.emf");
e.Graphics.DrawImage(metafile, 60, 10);
Dim metafile As New Metafile("SampleMetafile.emf")
e.Graphics.DrawImage(metafile, 60, 10)

Compiling the Code

The preceding example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler.

See Also

Working with Images, Bitmaps, Icons, and Metafiles