Metafile Class
Defines a graphic metafile. A metafile contains records that describe a sequence of graphics operations that can be recorded (constructed) and played back (displayed). This class is not inheritable.
Assembly: System.Drawing (in System.Drawing.dll)
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.
The following code example demonstrates how to create a Metafile and use the PlayRecord method.
Imports System Imports System.Drawing Imports System.Drawing.Imaging Imports System.Windows.Forms ' for Marshal.Copy Imports System.Runtime.InteropServices Public Class Form1 Inherits Form Private metafile1 As Metafile Private metafileDelegate As Graphics.EnumerateMetafileProc Private destPoint As Point Public Sub New() metafile1 = New Metafile("C:\test.wmf") metafileDelegate = New Graphics.EnumerateMetafileProc(AddressOf MetafileCallback) destPoint = New Point(20, 10) End Sub Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) e.Graphics.EnumerateMetafile(metafile1, destPoint, metafileDelegate) End Sub Private Function MetafileCallback(ByVal recordType As _ EmfPlusRecordType, ByVal flags As Integer, ByVal dataSize As Integer, _ ByVal data As IntPtr, ByVal callbackData As PlayRecordCallback) As Boolean Dim dataArray As Byte() = Nothing If data <> IntPtr.Zero Then ' Copy the unmanaged record to a managed byte buffer ' that can be used by PlayRecord. dataArray = New Byte(dataSize) {} Marshal.Copy(data, dataArray, 0, dataSize) End If metafile1.PlayRecord(recordType, flags, dataSize, dataArray) Return True End Function Shared Sub Main() Application.Run(New Form1()) End Sub End Class
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.