What's New
Q & A
Tip Jar
C# Helper...
Follow VBHelper on Twitter Follow VBHelper on Twitter
MSDN Visual Basic Community
TitleDisplay a Windows metafile (wmf file) in Visual Basic .NET
DescriptionThis example shows how to display a Windows metafile (wmf file) Visual Basic .NET.
Keywordsgraphics, image processing, wmf file, Windows metafile, metafile, example, example program, Windows Forms programming, Visual Basic .NET, VB.NET
CategoriesGraphics, Graphics

A Windows metafile (wmf file) is an image file that contains instructions for drawing shapes. In contrast bitmap, PNG, JPG, and other raster image files indicate exactly what colors individual pixels should have. Because a metafile contains drawing instructions instead of pixel values, you can resize a metafile without producing ugly anti-aliasing effects.

The picture shown here loads the same metafile as a bitmap and as a metafile and the enlarged slightly. When loaded as a bitmap (on the left), the enlarged version is blocky and pixellated. When loaded as a metafile, the result is smooth.

This example uses the following code to load an image as a bitmap and as a metafile.

' Load the images.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ' Load as a bitmap to see how big it is.
    Dim filename As String = "Epitrochoid.wmf"

    picImage.Image = New Bitmap(filename)
    picMetafile.Image = New Metafile(filename)
End Sub
First the program creates a new Bitmap object, passing its constructor the metafile's name. It then creates a new Metafile object, passing its constructor the metafile's name.

The program loads the same file twice, just in the first case it loads the file into a Bitmap.

For some strange reason, if you set a PictureBox's Image property to a metafile at design time, the program loads it as a Bitmap not as a Metafile. That means if you make the PictureBox display the image at other than its original size, you get aliasing effects.

Therefore to get the best result, you should load metafiles at run time as shown by this example.

Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.