Metafile.PlayRecord(EmfPlusRecordType, Int32, Int32, Byte[]) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
播放個別的中繼檔記錄。
public:
void PlayRecord(System::Drawing::Imaging::EmfPlusRecordType recordType, int flags, int dataSize, cli::array <System::Byte> ^ data);
public void PlayRecord (System.Drawing.Imaging.EmfPlusRecordType recordType, int flags, int dataSize, byte[] data);
member this.PlayRecord : System.Drawing.Imaging.EmfPlusRecordType * int * int * byte[] -> unit
Public Sub PlayRecord (recordType As EmfPlusRecordType, flags As Integer, dataSize As Integer, data As Byte())
參數
- recordType
- EmfPlusRecordType
EmfPlusRecordType 的項目,指定正要播放之中繼檔記錄的類型。
- flags
- Int32
旗標集,指定記錄的屬性 (Attribute)。
- dataSize
- Int32
記錄資料中的位元組數目。
- data
- Byte[]
含有記錄資料的位元組陣列。
範例
下列程式碼範例會示範如何使用 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