D3DImage 類別

定義

顯示使用者建立之 Direct3D 介面的 ImageSourceAn ImageSource that displays a user-created Direct3D surface.

public ref class D3DImage : System::Windows::Media::ImageSource
public class D3DImage : System.Windows.Media.ImageSource
type D3DImage = class
    inherit ImageSource
Public Class D3DImage
Inherits ImageSource
繼承

範例

下列程式碼範例顯示如何 D3DImage 在 XAML 中宣告。The following code example shows how to declare a D3DImage in XAML. 您必須對應 System.Windows.Interop 命名空間,因為它不包含在預設的 XAML 命名空間中。You must map the System.Windows.Interop namespace, because it is not included in the default XAML namespaces. 如需詳細資訊,請參閱 逐步解說:在 WPF 中裝載 Direct3D9 內容For more information, see Walkthrough: Hosting Direct3D9 Content in WPF.

    <Window x:Class="D3DHost.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:i="clr-namespace:System.Windows.Interop;assembly=PresentationCore"
    Title="MainWindow" Height="300" Width="300" Background="PaleGoldenrod">
    <Grid>
        <Image x:Name="imgelt">
            <Image.Source>
                <i:D3DImage x:Name="d3dimg" />
            </Image.Source>
        </Image>
    </Grid>
</Window>

備註

D3DImage 可以使用類別,在 Windows Presentation Foundation (WPF) 應用程式中裝載 Direct3D 內容。Use the D3DImage class to host Direct3D content in a Windows Presentation Foundation (WPF) application.

呼叫 Lock 方法來變更所顯示的 Direct3D 內容 D3DImageCall the Lock method to change the Direct3D content displayed by the D3DImage. 呼叫 SetBackBuffer 方法,將 Direct3D 介面指派給 D3DImageCall the SetBackBuffer method to assign a Direct3D surface to a D3DImage. 呼叫 AddDirtyRect 方法以追蹤 Direct3D 介面的更新。Call the AddDirtyRect method to track updates to the Direct3D surface. 呼叫 Unlock 方法,以顯示變更的區域。Call the Unlock method to display the changed areas.

D3DImage類別會管理兩個顯示緩衝區,稱為背景緩衝區前端緩衝區The D3DImage class manages two display buffers, which are called the back buffer and the front buffer. 背景緩衝區是您的 Direct3D 介面。The back buffer is your Direct3D surface. 當您呼叫方法時,會將背景緩衝區的變更複製到前端緩衝區 Unlock ,並在硬體上顯示該方法。Changes to the back buffer are copied forward to the front buffer when you call the Unlock method, where it is displayed on the hardware. 有時候,front 緩衝區會變成無法使用。Occasionally, the front buffer becomes unavailable. 這項缺少可用性的原因可能是螢幕鎖定、全螢幕專屬的 Direct3D 應用程式、使用者切換或其他系統活動。This lack of availability can be caused by screen locking, full-screen exclusive Direct3D applications, user-switching, or other system activities. 發生這種情況時,您的 WPF 應用程式會透過處理事件來通知 IsFrontBufferAvailableChangedWhen this occurs, your WPF application is notified by handling the IsFrontBufferAvailableChanged event. 應用程式回應前端緩衝區變得無法使用的方式,取決於是否已啟用 WPF 切換至軟體轉譯。How your application responds to the front buffer becoming unavailable depends on whether WPF is enabled to fall back to software rendering. SetBackBuffer方法具有多載,它會使用參數來指定 WPF 是否會切換至軟體轉譯。The SetBackBuffer method has an overload that takes a parameter that specifies whether WPF falls back to software rendering.

當 WPF 未切換至軟體轉譯時,回應無法使用的 Front 緩衝區Responding to an Unavailable Front Buffer when WPF Does not Fall Back to Software Rendering

當您呼叫多載 SetBackBuffer(D3DResourceType, IntPtr) 或呼叫多載 SetBackBuffer(D3DResourceType, IntPtr, Boolean) ,並將 enableSoftwareFallback 參數設定為時,轉譯 false 系統會在 front 緩衝區變成無法使用且沒有顯示任何內容時,釋放其對後緩衝區的參考。When you call the SetBackBuffer(D3DResourceType, IntPtr) overload or call the SetBackBuffer(D3DResourceType, IntPtr, Boolean) overload with the enableSoftwareFallback parameter set to false, the rendering system releases its reference to the back buffer when the front buffer becomes unavailable and nothing is displayed. 當前端緩衝區再次可用時,轉譯系統會引發 IsFrontBufferAvailableChanged 事件來通知您的 WPF 應用程式。When the front buffer is available again, the rendering system raises the IsFrontBufferAvailableChanged event to notify your WPF application. 您可以建立事件的事件處理常式, IsFrontBufferAvailableChanged 以使用有效的 Direct3D 介面再次重新呈現。You can create an event handler for the IsFrontBufferAvailableChanged event to restart rendering again with a valid Direct3D surface. 若要重新開機轉譯,您必須呼叫 SetBackBufferTo restart rendering, you must call SetBackBuffer.

當 WPF 切換至軟體轉譯時,回應無法使用的 Front 緩衝區Responding to an Unavailable Front Buffer when WPF Falls Back to Software Rendering

當您呼叫多載 SetBackBuffer(D3DResourceType, IntPtr, Boolean) 並將 enableSoftwareFallback 參數設定為時,轉譯系統會在 true 前端緩衝區變成無法使用時,保留對後緩衝區的參考,因此不需要在 SetBackBuffer 前端緩衝區再次可用時呼叫。When you call the SetBackBuffer(D3DResourceType, IntPtr, Boolean) overload with the enableSoftwareFallback parameter set to true, the rendering system retains its reference to the back buffer when the front buffer becomes unavailable, so there is no need to call SetBackBuffer when the front buffer is available again. 在某些情況下,使用者的裝置會無法使用。There may be situations where the user's device becomes unavailable. 發生這種情況時,呼叫 SetBackBuffer 以釋出 WPF 對背景緩衝區的參考。When that occurs, call SetBackBuffer to release WPF's reference to the back buffer. 如果您需要重設您的裝置,請 SetBackBuffer 使用 backBuffer 設定為的參數進行呼叫 null ,然後再呼叫一次,並 SetBackBuffer backBuffer 將設定為有效的 Direct3D 介面。If you need to reset your device, call SetBackBuffer with the backBuffer parameter set to null, and then call SetBackBuffer again with backBuffer set to a valid Direct3D surface.

注意

效能會大幅取決於 Direct3D 介面的設定。Performance depends greatly on the settings of the Direct3D surface. 如需詳細資訊,請參閱 Direct3D9 和 WPF 互通性的效能考慮For more information, see Performance Considerations for Direct3D9 and WPF Interoperability.

注意

D3DImage當 WPF 在軟體中轉譯時,類別不會顯示 Direct3D 內容,例如透過遠端桌面連線,除非您呼叫 SetBackBuffer(D3DResourceType, IntPtr, Boolean) 並指定 true enableSoftwareFallback 參數。The D3DImage class does not display Direct3D content when WPF renders in software, such as over a Remote Desktop connection, unless you call SetBackBuffer(D3DResourceType, IntPtr, Boolean) and specify true for the enableSoftwareFallback parameter.

建構函式

D3DImage()

初始化 D3DImage 類別的新執行個體。Initializes a new instance of the D3DImage class.

D3DImage(Double, Double)

使用指定的顯示解析度,初始化 D3DImage 類別的新執行個體。Initializes a new instance of the D3DImage class with the specified display resolution.

欄位

IsFrontBufferAvailableProperty

識別 IsFrontBufferAvailable 相依性屬性。Identifies the IsFrontBufferAvailable dependency property.

屬性

CanFreeze

取得值,指出是否可以將物件設為不可修改。Gets a value that indicates whether the object can be made unmodifiable.

(繼承來源 Freezable)
DependencyObjectType

取得包裝此執行個體之 CLRCLR 型別的 DependencyObjectTypeGets the DependencyObjectType that wraps the CLRCLR type of this instance.

(繼承來源 DependencyObject)
Dispatcher

取得與這個 Dispatcher 關聯的 DispatcherObjectGets the Dispatcher this DispatcherObject is associated with.

(繼承來源 DispatcherObject)
HasAnimatedProperties

取得值,這個值表示是否有一個或多個 AnimationClock 物件與這個物件的任何一個相依性屬性相關聯。Gets a value that indicates whether one or more AnimationClock objects is associated with any of this object's dependency properties.

(繼承來源 Animatable)
Height

取得 D3DImage 的高度。Gets the height of the D3DImage.

IsFrontBufferAvailable

取得指出前景緩衝區是否存在的值。Gets a value that indicates whether a front buffer exists.

IsFrozen

取得值,該值表示物件目前是否可修改。Gets a value that indicates whether the object is currently modifiable.

(繼承來源 Freezable)
IsSealed

取得值,這個值表示此執行個體目前是否已密封 (唯讀)。Gets a value that indicates whether this instance is currently sealed (read-only).

(繼承來源 DependencyObject)
Metadata

取得與影像來源關聯的中繼資料。Gets the metadata associated with the image source.

PixelHeight

取得 D3DImage的高度,以像素為單位。Gets the height of the D3DImage, in pixels.

PixelWidth

取得 D3DImage 的寬度,以像素為單位。Gets the width of the D3DImage, in pixels.

Width

取得 D3DImage 的寬度。Gets the width of the D3DImage.

方法

AddDirtyRect(Int32Rect)

指定所變更之背景緩衝區的區域。Specifies the area of the back buffer that changed.

ApplyAnimationClock(DependencyProperty, AnimationClock)

AnimationClock 套用至指定的 DependencyPropertyApplies an AnimationClock to the specified DependencyProperty. 如果屬性已有動畫效果,即使用 SnapshotAndReplace 遞移式行為。If the property is already animated, the SnapshotAndReplace handoff behavior is used.

(繼承來源 Animatable)
ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior)

AnimationClock 套用至指定的 DependencyPropertyApplies an AnimationClock to the specified DependencyProperty. 如果已建立屬性的動畫,則會使用指定的 HandoffBehaviorIf the property is already animated, the specified HandoffBehavior is used.

(繼承來源 Animatable)
BeginAnimation(DependencyProperty, AnimationTimeline)

將動畫套用至指定的 DependencyPropertyApplies an animation to the specified DependencyProperty. 呈現下一個畫面格後,就會啟動動畫。The animation is started when the next frame is rendered. 如果指定的屬性已有動畫效果,即使用 SnapshotAndReplace 遞移式行為。If the specified property is already animated, the SnapshotAndReplace handoff behavior is used.

(繼承來源 Animatable)
BeginAnimation(DependencyProperty, AnimationTimeline, HandoffBehavior)

將動畫套用至指定的 DependencyPropertyApplies an animation to the specified DependencyProperty. 呈現下一個畫面格後,就會啟動動畫。The animation is started when the next frame is rendered. 如果已建立指定之屬性的動畫,則會使用指定的 HandoffBehaviorIf the specified property is already animated, the specified HandoffBehavior is used.

(繼承來源 Animatable)
CheckAccess()

判斷呼叫的執行是否可以存取這個 DispatcherObjectDetermines whether the calling thread has access to this DispatcherObject.

(繼承來源 DispatcherObject)
ClearValue(DependencyProperty)

清除屬性的區域數值。Clears the local value of a property. 要清除的屬性是由 DependencyProperty 識別項所指定。The property to be cleared is specified by a DependencyProperty identifier.

(繼承來源 DependencyObject)
ClearValue(DependencyPropertyKey)

清除唯讀屬性的區域數值。Clears the local value of a read-only property. 要清除的屬性是由 DependencyPropertyKey 所指定。The property to be cleared is specified by a DependencyPropertyKey.

(繼承來源 DependencyObject)
Clone()

建立這個 D3DImage 物件的可修改複製品,製作這個物件值的深層複本。Creates a modifiable clone of this D3DImage object, making deep copies of this object's values. 當複製相依性屬性時,這個方法會複製資源參考和資料繫結 (它們可能已不再解析),但不會複製動畫或其目前值。When copying dependency properties, this method copies resource references and data bindings (which may no longer resolve), but not animations or their current values.

CloneCore(Freezable)

使用基底 (非動畫) 屬性值,將執行個體設為指定 Freezable 的複製品 (深層複製)。Makes the instance a clone (deep copy) of the specified Freezable using base (non-animated) property values.

CloneCurrentValue()

建立這個 D3DImage 物件的可修改複製品,製作這個物件目前值的深層複本。Creates a modifiable clone of this D3DImage object, making deep copies of this object's current values. 不會複製資源參考、資料繫結和動畫,但是會複製其目前值。Resource references, data bindings, and animations are not copied, but their current values are copied.

CloneCurrentValueCore(Freezable)

使用目前的屬性值,讓執行個體成為指定之 Freezable 的可修改複本 (深層複本)。Makes the instance a modifiable clone (deep copy) of the specified Freezable using current property values.

CoerceValue(DependencyProperty)

強制轉型所指定相依性屬性的值。Coerces the value of the specified dependency property. 完成方式是叫用存在於呼叫 DependencyObject 之相依性屬性的屬性中繼資料中所指定的任何 CoerceValueCallback 函式。This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject.

(繼承來源 DependencyObject)
CopyBackBuffer()

建立 D3DImage 的軟體版本。Creates a software copy of the D3DImage.

CreateInstance()

初始化 Freezable 類別的新執行個體。Initializes a new instance of the Freezable class.

(繼承來源 Freezable)
CreateInstanceCore()

在衍生類別中實作時,建立 D3DImage 衍生類別的新執行個體。When implemented in a derived class, creates a new instance of the D3DImage derived class.

Equals(Object)

判斷提供的 DependencyObject 和目前的 DependencyObject 是否相等。Determines whether a provided DependencyObject is equivalent to the current DependencyObject.

(繼承來源 DependencyObject)
Finalize()

釋出資源並執行其他清除作業後,記憶體回收才能重新回收 D3DImageFrees resources and performs other cleanup operations before the D3DImage is reclaimed by garbage collection.

Freeze()

將目前的物件設為不可修改,並將其 IsFrozen 屬性設定為 trueMakes the current object unmodifiable and sets its IsFrozen property to true.

(繼承來源 Freezable)
FreezeCore(Boolean)

D3DImage 設為不可以修改的項目,或是判斷它是否可以改為不可修改的項目。Makes the D3DImage unmodifiable or determines whether it can be made unmodifiable.

GetAnimationBaseValue(DependencyProperty)

傳回指定之 DependencyProperty 的非動畫實值。Returns the non-animated value of the specified DependencyProperty.

(繼承來源 Animatable)
GetAsFrozen()

使用基底 (非動畫) 屬性值,建立 Freezable 的凍結複本。Creates a frozen copy of the Freezable, using base (non-animated) property values. 因為複本已凍結,所以會以傳址方式複製任何凍結子物件。Because the copy is frozen, any frozen sub-objects are copied by reference.

(繼承來源 Freezable)
GetAsFrozenCore(Freezable)

使用基底 (非動畫) 屬性值,將執行個體設為指定 Freezable 的凍結複本。Makes the instance a frozen clone of the specified Freezable using base (non-animated) property values.

GetCurrentValueAsFrozen()

使用目前屬性值,建立 Freezable 的凍結複本。Creates a frozen copy of the Freezable using current property values. 因為複本已凍結,所以會以傳址方式複製任何凍結子物件。Because the copy is frozen, any frozen sub-objects are copied by reference.

(繼承來源 Freezable)
GetCurrentValueAsFrozenCore(Freezable)

將目前執行個體設為所指定 Freezable 的凍結複本。Makes the current instance a frozen clone of the specified Freezable. 如果物件具有動畫相依性屬性,則會複製其目前的動畫值。If the object has animated dependency properties, their current animated values are copied.

GetHashCode()

取得這個 DependencyObject 的雜湊碼。Gets a hash code for this DependencyObject.

(繼承來源 DependencyObject)
GetLocalValueEnumerator()

建立特定的列舉值,以判斷哪些相依性屬性在此 DependencyObject 上具有本機設定的值。Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(繼承來源 DependencyObject)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
GetValue(DependencyProperty)

傳回 DependencyObject 的這個執行個體上之相依性屬性的目前有效值。Returns the current effective value of a dependency property on this instance of a DependencyObject.

(繼承來源 DependencyObject)
InvalidateProperty(DependencyProperty)

重新評估指定相依性屬性的有效值。Re-evaluates the effective value for the specified dependency property.

(繼承來源 DependencyObject)
Lock()

鎖定 D3DImage,並且在背景緩衝區上啟用操作。Locks the D3DImage and enables operations on the back buffer.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnChanged()

目前的 Freezable 物件遭到修改時進行呼叫。Called when the current Freezable object is modified.

(繼承來源 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject)

確定已為剛剛設定的 DependencyObjectType 資料成員,建立適當的內容指標。Ensures that appropriate context pointers are established for a DependencyObjectType data member that has just been set.

(繼承來源 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)

這個成員支援 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 基礎結構,但是您不可以從程式碼直接使用它。This member supports the Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) infrastructure and is not intended to be used directly from your code.

(繼承來源 Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

覆寫 OnPropertyChanged(DependencyPropertyChangedEventArgs)DependencyObject 實作也可以叫用任何 Changed 處理常式,以回應類型 Freezable 的變更相依性屬性。Overrides the DependencyObject implementation of OnPropertyChanged(DependencyPropertyChangedEventArgs) to also invoke any Changed handlers in response to a changing dependency property of type Freezable.

(繼承來源 Freezable)
ReadLocalValue(DependencyProperty)

傳回相依性屬性的區域值 (如果存在)。Returns the local value of a dependency property, if it exists.

(繼承來源 DependencyObject)
ReadPreamble()

確定 Freezable 是從有效的執行緒進行存取。Ensures that the Freezable is being accessed from a valid thread. 如果 API 會讀取非相依性屬性的資料成員,則 Freezable 的繼承者必須在該 API 的開頭呼叫這個方法。Inheritors of Freezable must call this method at the beginning of any API that reads data members that are not dependency properties.

(繼承來源 Freezable)
SetBackBuffer(D3DResourceType, IntPtr)

指派 Direct3D 介面做為背景緩衝區的來源。Assigns a Direct3D surface as the source of the back buffer.

SetBackBuffer(D3DResourceType, IntPtr, Boolean)

指派 Direct3D 介面做為背景緩衝區的來源。Assigns a Direct3D surface as the source of the back buffer.

SetCurrentValue(DependencyProperty, Object)

設定相依性屬性的值,而不需要變更其值來源。Sets the value of a dependency property without changing its value source.

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

設定相依性屬性的區域值 (由相依性屬性的識別碼所指定)。Sets the local value of a dependency property, specified by its dependency property identifier.

(繼承來源 DependencyObject)
SetValue(DependencyPropertyKey, Object)

設定唯讀相依性屬性的區域數值 (由相依性屬性的 DependencyPropertyKey 識別項所指定)。Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(繼承來源 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

傳回值,這個值表示序列化程序是否應該序列化所提供相依性屬性的值。Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(繼承來源 DependencyObject)
ToString()

根據目前的文化特性,建立這個物件的字串表示。Creates a string representation of this object based on the current culture.

(繼承來源 ImageSource)
ToString(IFormatProvider)

根據傳入的 IFormatProvider,建立這個物件的字串表示。Creates a string representation of this object based on the IFormatProvider passed in. 如果提供者為 null,則會使用 CurrentCultureIf the provider is null, the CurrentCulture is used.

(繼承來源 ImageSource)
TryLock(Duration)

嘗試鎖定 D3DImage,並且依指定的期間等候鎖定進行。Attempts to lock the D3DImage and waits for the specified duration.

Unlock()

遞減 D3DImage 的鎖定計數。Decrements the lock count for the D3DImage.

VerifyAccess()

請強制執行可以存取這個 DispatcherObject 的呼叫執行緒。Enforces that the calling thread has access to this DispatcherObject.

(繼承來源 DispatcherObject)
WritePostscript()

引發 FreezableChanged 事件,並叫用其 OnChanged() 方法。Raises the Changed event for the Freezable and invokes its OnChanged() method. 在任何 API 修改未以相依性屬性儲存的類別成員之後,衍生自 Freezable 的類別應該在 API 的結尾呼叫這個方法。Classes that derive from Freezable should call this method at the end of any API that modifies class members that are not stored as dependency properties.

(繼承來源 Freezable)
WritePreamble()

確認 Freezable 未凍結,而且是從有效的執行緒內容進行存取。Verifies that the Freezable is not frozen and that it is being accessed from a valid threading context. 在任何 API 將資料寫入至非相依性屬性的資料成員之前,Freezable 繼承者應該在 API 的開頭呼叫這個方法。Freezable inheritors should call this method at the beginning of any API that writes to data members that are not dependency properties.

(繼承來源 Freezable)

事件

Changed

發生於 Freezable 或所含的物件遭到修改時。Occurs when the Freezable or an object it contains is modified.

(繼承來源 Freezable)
IsFrontBufferAvailableChanged

發生於 IsFrontBufferAvailable 屬性變更時。Occurs when the IsFrontBufferAvailable property changes.

明確介面實作

IFormattable.ToString(String, IFormatProvider)

使用指定的格式,格式化目前執行個體的值。Formats the value of the current instance using the specified format.

(繼承來源 ImageSource)

適用於