Metafile 類別

定義

定義圖形中繼檔 (Metafile)。 中繼檔,包含用在說明一系列可記錄 (建構) 和重播 (顯示) 之圖形操作的記錄。 這個類別是不可繼承的。

public ref class Metafile sealed : System::Drawing::Image
public sealed class Metafile : System.Drawing.Image
[System.Runtime.InteropServices.ComVisible(false)]
[System.Serializable]
public sealed class Metafile : System.Drawing.Image
[System.Serializable]
public sealed class Metafile : System.Drawing.Image
type Metafile = class
    inherit Image
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Serializable>]
type Metafile = class
    inherit Image
[<System.Serializable>]
type Metafile = class
    inherit Image
Public NotInheritable Class Metafile
Inherits Image
繼承
屬性

範例

下列程式碼範例示範如何建立 Metafile 和使用 PlayRecord 方法。


using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

// for Marshal.Copy
using System.Runtime.InteropServices; 

public class Form1 : Form
{
    private Metafile metafile1;
    private Graphics.EnumerateMetafileProc metafileDelegate;
    private Point destPoint;
    public Form1()
    {
        metafile1 = new Metafile(@"C:\Test.wmf");
        metafileDelegate = new Graphics.EnumerateMetafileProc(MetafileCallback);
        destPoint = new Point(20, 10);
    }
    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.EnumerateMetafile(metafile1, destPoint, metafileDelegate);
    }
    private bool MetafileCallback(
       EmfPlusRecordType recordType,
       int flags,
       int dataSize,
       IntPtr data,
       PlayRecordCallback callbackData)
    {
        byte[] dataArray = null;
        if (data != IntPtr.Zero)
        {
            // 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);
        }

        metafile1.PlayRecord(recordType, flags, dataSize, dataArray);

        return true;
    }

    static void Main()
    {
        Application.Run(new Form1());
    }
}
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

備註

當您使用 Save 方法將圖形影像儲存為 Windows Metafile Format (WMF) 或增強元檔案格式 (EMF) 檔案時,產生的檔案會改為儲存為可攜式網狀圖形 (PNG) 檔案。 發生此行為的原因是.NET Framework的 GDI+ 元件沒有可用來將檔案儲存為 .wmf 或 .emf 檔案的編碼器。

注意

在 .NET 6 和更新版本中,只有 Windows 作業系統才支援包含此類型的 System.Drawing.Common 套件。 在跨平臺應用程式中使用此類型會導致編譯時間警告和執行時間例外狀況。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common

建構函式

Metafile(IntPtr, Boolean)

從指定的控制代碼初始化 Metafile 類別的新執行個體。

Metafile(IntPtr, EmfType)

從指定的裝置內容控制代碼和指定 Metafile 格式的 EmfType 列舉型別 (Enumeration),初始化 Metafile 類別的新執行個體。

Metafile(IntPtr, EmfType, String)

從指定的裝置內容控制代碼和指定 Metafile 格式的 EmfType 列舉型別 (Enumeration),初始化 Metafile 類別的新執行個體。 字串可以提供來命名檔案。

Metafile(IntPtr, Rectangle)

從指定的裝置內容 (其界限是由指定的矩形加以限定) 來初始化 Metafile 類別的新執行個體。

Metafile(IntPtr, Rectangle, MetafileFrameUnit)

從指定的裝置內容 (其界限是由使用提供之測量單位的指定矩形加以限定),初始化 Metafile 類別的新執行個體。

Metafile(IntPtr, Rectangle, MetafileFrameUnit, EmfType)

從指定的裝置內容 (其界限是由使用提供之測量單位的指定矩形加以限定) 和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。

Metafile(IntPtr, Rectangle, MetafileFrameUnit, EmfType, String)

從指定的裝置內容 (其界限是由使用提供之測量單位的指定矩形加以限定) 和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。 字串可以提供來命名檔案。

Metafile(IntPtr, RectangleF)

從指定的裝置內容 (其界限是由指定的矩形加以限定) 來初始化 Metafile 類別的新執行個體。

Metafile(IntPtr, RectangleF, MetafileFrameUnit)

從指定的裝置內容 (其界限是由使用提供之測量單位的指定矩形加以限定),初始化 Metafile 類別的新執行個體。

Metafile(IntPtr, RectangleF, MetafileFrameUnit, EmfType)

從指定的裝置內容 (其界限是由使用提供之測量單位的指定矩形加以限定) 和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。

Metafile(IntPtr, RectangleF, MetafileFrameUnit, EmfType, String)

從指定的裝置內容 (其界限是由使用提供之測量單位的指定矩形加以限定) 和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。 字串可以提供來命名檔案。

Metafile(IntPtr, WmfPlaceableFileHeader)

從指定的控制代碼和 Metafile 初始化 WmfPlaceableFileHeader 類別的新執行個體。

Metafile(IntPtr, WmfPlaceableFileHeader, Boolean)

從指定的控制代碼和 Metafile 初始化 WmfPlaceableFileHeader 類別的新執行個體。 而且,deleteWmf 參數還可以在刪除中繼檔時用來刪除控制代碼。

Metafile(Stream)

從指定的資料流,初始化 Metafile 類別的新執行個體。

Metafile(Stream, IntPtr)

從指定的資料流,初始化 Metafile 類別的新執行個體。

Metafile(Stream, IntPtr, EmfType)

從指定的資料流、裝置內容的 Windows 控制代碼和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。

Metafile(Stream, IntPtr, EmfType, String)

從指定的資料流、裝置內容的 Windows 控制代碼和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。 也可以加入含有新 Metafile 之描述性名稱的字串。

Metafile(Stream, IntPtr, Rectangle)

從指定的資料流、裝置內容的 Windows 控制代碼和表示限定新 Metafile 界限之矩形的 Rectangle 結構,初始化 Metafile 類別的新執行個體。

Metafile(Stream, IntPtr, Rectangle, MetafileFrameUnit)

從指定的資料流、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 Rectangle 結構和提供的測量單位,初始化 Metafile 類別的新執行個體。

Metafile(Stream, IntPtr, Rectangle, MetafileFrameUnit, EmfType)

從指定的資料流、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 Rectangle 結構、提供的測量單位和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。

Metafile(Stream, IntPtr, Rectangle, MetafileFrameUnit, EmfType, String)

從指定的資料流、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 Rectangle 結構、提供的測量單位和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。 可以加入含有新 Metafile 之描述性名稱的字串。

Metafile(Stream, IntPtr, RectangleF)

從指定的資料流、裝置內容的 Windows 控制代碼和表示限定新 Metafile 界限之矩形的 RectangleF 結構,初始化 Metafile 類別的新執行個體。

Metafile(Stream, IntPtr, RectangleF, MetafileFrameUnit)

從指定的資料流、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 RectangleF 結構和提供的測量單位,初始化 Metafile 類別的新執行個體。

Metafile(Stream, IntPtr, RectangleF, MetafileFrameUnit, EmfType)

從指定的資料流、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 RectangleF 結構、提供的測量單位和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。

Metafile(Stream, IntPtr, RectangleF, MetafileFrameUnit, EmfType, String)

從指定的資料流、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 RectangleF 結構、提供的測量單位和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。 可以加入含有新 Metafile 之描述性名稱的字串。

Metafile(String)

從指定的檔案名稱初始化 Metafile 類別的新執行個體。

Metafile(String, IntPtr)

使用指定的檔案名稱,初始化 Metafile 類別的新執行個體。

Metafile(String, IntPtr, EmfType)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼和指定 Metafile 之格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。

Metafile(String, IntPtr, EmfType, String)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼和指定 Metafile 之格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。 也可以加入描述性字串。

Metafile(String, IntPtr, Rectangle)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼和表示限定新 Metafile 界限之矩形的 Rectangle 結構,初始化 Metafile 類別的新執行個體。

Metafile(String, IntPtr, Rectangle, MetafileFrameUnit)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限的矩形之 Rectangle 結構和提供的測量單位,初始化 Metafile 類別的新執行個體。

Metafile(String, IntPtr, Rectangle, MetafileFrameUnit, EmfType)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 Rectangle 結構、提供的測量單位和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。

Metafile(String, IntPtr, Rectangle, MetafileFrameUnit, EmfType, String)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 Rectangle 結構、提供的測量單位和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。 也可以加入描述性字串。

Metafile(String, IntPtr, Rectangle, MetafileFrameUnit, String)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限的矩形之 Rectangle 結構和提供的測量單位,初始化 Metafile 類別的新執行個體。 也可以加入描述性字串。

Metafile(String, IntPtr, RectangleF)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼和表示限定新 Metafile 界限之矩形的 RectangleF 結構,初始化 Metafile 類別的新執行個體。

Metafile(String, IntPtr, RectangleF, MetafileFrameUnit)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限的矩形之 RectangleF 結構和提供的測量單位,初始化 Metafile 類別的新執行個體。

Metafile(String, IntPtr, RectangleF, MetafileFrameUnit, EmfType)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 RectangleF 結構、提供的測量單位和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。

Metafile(String, IntPtr, RectangleF, MetafileFrameUnit, EmfType, String)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限之矩形的 RectangleF 結構、提供的測量單位和指定 Metafile 格式的 EmfType 列舉型別,初始化 Metafile 類別的新執行個體。 也可以加入描述性字串。

Metafile(String, IntPtr, RectangleF, MetafileFrameUnit, String)

使用指定的檔案名稱、裝置內容的 Windows 控制代碼、表示限定新 Metafile 界限的矩形之 RectangleF 結構和提供的測量單位,初始化 Metafile 類別的新執行個體。 也可以加入描述性字串。

屬性

Flags

取得這個 Image 之像素資料的屬性旗標。

(繼承來源 Image)
FrameDimensionsList

取得 GUID 的陣列,表示這個 Image 中的框架 (Frame) 維度 (Dimension)。

(繼承來源 Image)
Height

取得這個 Image 的高度 (單位為像素)。

(繼承來源 Image)
HorizontalResolution

取得這個 Image 的水平解析度 (單位為每英吋的像素)。

(繼承來源 Image)
Palette

取得或設定用於這個 Image 的調色盤。

(繼承來源 Image)
PhysicalDimension

取得這個影像的寬度和高度。

(繼承來源 Image)
PixelFormat

取得這個 Image 的像素格式。

(繼承來源 Image)
PropertyIdList

取得儲存在這個 Image 中的屬性項目 ID。

(繼承來源 Image)
PropertyItems

取得儲存在這個 Image 中的所有屬性項目 (中繼資料的各個項目)。

(繼承來源 Image)
RawFormat

取得這個 Image 的檔案格式。

(繼承來源 Image)
Size

取得影像的寬度和高度,單位為像素。

(繼承來源 Image)
Tag

取得或設定物件,該物件提供影像的其他相關資料。

(繼承來源 Image)
VerticalResolution

取得這個 Image 的垂直解析度 (單位為每英吋的像素)。

(繼承來源 Image)
Width

取得這個 Image 的寬度 (單位為像素)。

(繼承來源 Image)

方法

Clone()

建立這個 Image 的完全相同複本。

(繼承來源 Image)
CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放這個 Image 所使用的所有資源。

(繼承來源 Image)
Dispose(Boolean)

釋放 Image 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 Image)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetBounds(GraphicsUnit)

取得使用指定單位之影像的界限。

(繼承來源 Image)
GetEncoderParameterList(Guid)

傳回指定的影像編碼器支援的參數資訊。

(繼承來源 Image)
GetFrameCount(FrameDimension)

傳回指定維度的框架數。

(繼承來源 Image)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetHenhmetafile()

傳回增強型 Metafile 的 Windows 控制代碼。

GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 MarshalByRefObject)
GetMetafileHeader()

傳回與這個 MetafileHeader 相關聯的 Metafile

GetMetafileHeader(IntPtr)

傳回與指定 MetafileHeader 相關的 Metafile

GetMetafileHeader(IntPtr, WmfPlaceableFileHeader)

傳回與指定 MetafileHeader 相關的 Metafile

GetMetafileHeader(Stream)

傳回與指定 MetafileHeader 相關的 Metafile

GetMetafileHeader(String)

傳回與指定 MetafileHeader 相關的 Metafile

GetPropertyItem(Int32)

從這個 Image 取得指定的屬性項目。

(繼承來源 Image)
GetThumbnailImage(Int32, Int32, Image+GetThumbnailImageAbort, IntPtr)

傳回這個 Image 的縮圖。

(繼承來源 Image)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得存留期服務物件,以控制這個執行個體的存留期原則。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。

(繼承來源 MarshalByRefObject)
PlayRecord(EmfPlusRecordType, Int32, Int32, Byte[])

播放個別的中繼檔記錄。

RemovePropertyItem(Int32)

將指定的屬性項目從這個 Image 中移除。

(繼承來源 Image)
RotateFlip(RotateFlipType)

旋轉、翻轉或者同時旋轉和翻轉 Image

(繼承來源 Image)
Save(Stream, ImageCodecInfo, EncoderParameters)

使用指定的編碼器和影像編碼器參數,將此影像儲存至指定的資料流。

(繼承來源 Image)
Save(Stream, ImageFormat)

將這個影像以指定的格式儲存至指定的資料流。

(繼承來源 Image)
Save(String)

儲存這個 Image 至指定的檔案或資料流。

(繼承來源 Image)
Save(String, ImageCodecInfo, EncoderParameters)

使用指定的編碼器和影像編碼器參數,將此 Image 儲存至指定的檔案。

(繼承來源 Image)
Save(String, ImageFormat)

將這個 Image 以指定的格式儲存至指定的檔案。

(繼承來源 Image)
SaveAdd(EncoderParameters)

將框架加入先前的 Save 方法呼叫所指定的檔案或資料流。 使用這個方法以從多重框架影像儲存選取框架至另一個多重框架影像。

(繼承來源 Image)
SaveAdd(Image, EncoderParameters)

將框架加入先前的 Save 方法呼叫所指定的檔案或資料流。

(繼承來源 Image)
SelectActiveFrame(FrameDimension, Int32)

選取由維度和索引所指定的框架。

(繼承來源 Image)
SetPropertyItem(PropertyItem)

在這個 Image 中儲存屬性項目 (中繼資料的項目)。

(繼承來源 Image)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

將序列化目標物件所需的資料填入 SerializationInfo

(繼承來源 Image)

適用於