BitmapImage 類別

定義

提供一種專門化的程式 BitmapSource ,專為使用可擴充應用程式標記語言(XAML)載入影像而優化。

public ref class BitmapImage sealed : System::Windows::Media::Imaging::BitmapSource, System::ComponentModel::ISupportInitialize, System::Windows::Markup::IUriContext
public sealed class BitmapImage : System.Windows.Media.Imaging.BitmapSource, System.ComponentModel.ISupportInitialize, System.Windows.Markup.IUriContext
type BitmapImage = class
    inherit BitmapSource
    interface ISupportInitialize
    interface IUriContext
Public NotInheritable Class BitmapImage
Inherits BitmapSource
Implements ISupportInitialize, IUriContext
繼承
實作

範例

以下程式碼範例示範如何在可擴充應用標記語言(XAML)及程式碼中使用 BitmapImage

<!-- Property Tag XAML Syntax -->
<Image Width="200"  Margin="5" Grid.Column="1" Grid.Row="1" >
   <Image.Source>
      <BitmapImage UriSource="sampleImages/bananas.jpg" />
   </Image.Source>
</Image>
<!-- Property Tag XAML Syntax -->
<Image Width="200"  Margin="5" Grid.Column="1" Grid.Row="1" >
   <Image.Source>
      <BitmapImage UriSource="sampleImages/bananas.jpg" />
   </Image.Source>
</Image>
// Create the image element.
Image simpleImage = new Image();    
simpleImage.Width = 200;
simpleImage.Margin = new Thickness(5);

// Create source.
BitmapImage bi = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block.
bi.BeginInit();
bi.UriSource = new Uri(@"/sampleImages/cherries_larger.jpg",UriKind.RelativeOrAbsolute);
bi.EndInit();
// Set the image source.
simpleImage.Source = bi;
' Create the image element.
Dim simpleImage As New Image()
simpleImage.Width = 200
simpleImage.Margin = New Thickness(5)

' Create source.
Dim bi As New BitmapImage()
' BitmapImage.UriSource must be in a BeginInit/EndInit block.
bi.BeginInit()
bi.UriSource = New Uri("/sampleImages/cherries_larger.jpg", UriKind.RelativeOrAbsolute)
bi.EndInit()
' Set the image source.
simpleImage.Source = bi

備註

BitmapImage 主要存在的目的是支援可擴充應用標記語言(XAML)語法,並引入了未由 BitmapSourceS 定義的額外點陣圖載入特性。

BitmapImage 實作 ISupportInitialize 介面以優化多個屬性的初始化。 屬性變更只能在物件初始化過程中發生。 呼叫 BeginInit 以表示初始化已開始,並 EndInit 表示初始化已完成。 初始化後,屬性變更會被忽略。

BitmapImage 使用 BitmapImage 建構器建立的物件會自動初始化,屬性變更則被忽略。

建構函式

名稱 Description
BitmapImage()

初始化 BitmapImage 類別的新執行個體。

BitmapImage(Uri, RequestCachePolicy)

初始化一個新的類別實例 BitmapImage ,其來源為 Uri,並依所提供的 RequestCachePolicy快取。

BitmapImage(Uri)

利用提供的 BitmapImage初始化類別的新實例Uri

欄位

名稱 Description
CacheOptionProperty

識別 CacheOption 依賴性質。

CreateOptionsProperty

識別 CreateOptions 依賴性質。

DecodePixelHeightProperty

識別 DecodePixelHeight 依賴性質。

DecodePixelWidthProperty

識別 DecodePixelWidth 依賴性質。

RotationProperty

識別 Rotation 依賴性質。

SourceRectProperty

識別 SourceRect 依賴性質。

StreamSourceProperty

識別 StreamSource 依賴性質。

UriCachePolicyProperty

識別 UriCachePolicy 依賴性質。

UriSourceProperty

識別 UriSource 依賴性質。

屬性

名稱 Description
BaseUri

取得或設定一個代表當前Uri上下文基底BitmapImage的值。

CacheOption

取得或設定 BitmapCacheOption 為此實例 BitmapImage使用 。

CanFreeze

會得到一個值,表示該物件是否能被設定為不可修改。

(繼承來源 Freezable)
CreateOptions

得到或 BitmapCreateOptions 設定 ,為 BitmapImage

DecodePixelHeight

取得或設定影像解碼時的高度(以像素為單位)。

DecodePixelWidth

取得或設定影像解碼時的寬度(以像素為單位)。

DependencyObjectType

會取得 DependencyObjectType 包裹此實例 CLR 類型的 。

(繼承來源 DependencyObject)
Dispatcher

了解 Dispatcher 這與此 DispatcherObject 有關。

(繼承來源 DispatcherObject)
DpiX

取得圖片的水平點數每英吋(dpi)。

(繼承來源 BitmapSource)
DpiY

取得影像垂直點數每英吋(dpi)。

(繼承來源 BitmapSource)
Format

取得點陣圖資料的原生 PixelFormat 版本。

(繼承來源 BitmapSource)
HasAnimatedProperties

會得到一個值,表示是否有一個或多個 AnimationClock 物件與該物件的相依屬性相關聯。

(繼承來源 Animatable)
Height

取得來源位圖高度,單位與裝置無關(每單位 1/96 英吋)。

(繼承來源 BitmapSource)
IsDownloading

會得到一個值,表示你 BitmapImage 目前是否正在下載內容。

IsFrozen

會得到一個值,表示該物件目前是否可修改。

(繼承來源 Freezable)
IsSealed

會獲得一個值,表示該實例目前是否封存(唯讀)。

(繼承來源 DependencyObject)
Metadata

不支援。 BitmapImage 不支持該 Metadata 性質,且會拋出 NotSupportedException

Palette

如果有指定,會取得點陣圖的色彩調色盤。

(繼承來源 BitmapSource)
PixelHeight

它會取得點陣圖的高度(像素單位)。

(繼承來源 BitmapSource)
PixelWidth

會得到點陣圖的寬度(像素數)。

(繼承來源 BitmapSource)
Rotation

它設定了旋轉 BitmapImage 的角度。

SourceRect

取得或設定用作來源 BitmapImage的矩形。

StreamSource

取得或設定 的 BitmapImage串流來源。

UriCachePolicy

取得或設定一個值,代表來自 HTTP 來源的影像快取政策。

UriSource

取得或設定 Uri 的來源 BitmapImage

Width

以裝置獨立單位取得位圖寬度(每單位 1/96 英吋)。

(繼承來源 BitmapSource)

方法

名稱 Description
ApplyAnimationClock(DependencyProperty, AnimationClock, HandoffBehavior)

應用於 AnimationClock 指定的 DependencyProperty。 如果該屬性已經被動畫化,則會使用指定的 HandoffBehavior 屬性。

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

應用於 AnimationClock 指定的 DependencyProperty。 如果該屬性已經被動畫化,則 SnapshotAndReplace 會使用切換行為。

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

對指定的 DependencyProperty. 動畫會在下一幀渲染時開始。 如果指定的屬性已經被動畫化,則會使用指定的 HandoffBehavior 屬性。

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

對指定的 DependencyProperty. 動畫會在下一幀渲染時開始。 如果指定的屬性已經動畫化,則 SnapshotAndReplace 會採用切換行為。

(繼承來源 Animatable)
BeginInit()

表示初始化開始 BitmapImage

CheckAccess()

判斷呼叫執行緒是否能存取此 DispatcherObject

(繼承來源 DispatcherObject)
CheckIfSiteOfOrigin()

檢查點陣圖來源內容是否來自已知的來源地。 此方法用於確保像素複製操作的安全。

(繼承來源 BitmapSource)
ClearValue(DependencyProperty)

清算房產的當地價值。 要清除的屬性由識別 DependencyProperty 碼指定。

(繼承來源 DependencyObject)
ClearValue(DependencyPropertyKey)

清除只讀屬性的局部值。 要清除的屬性由 DependencyPropertyKey指定。

(繼承來源 DependencyObject)
Clone()

建立一個可修改的克隆, BitmapImage製作該物件值的深度複製。

CloneCore(Freezable)

使此實例成為指定 BitmapSource的深度複製。 當複製相依屬性時,此方法會複製資源參考與資料綁定(但可能不再解析),但不會複製動畫或其當前值。

(繼承來源 BitmapSource)
CloneCurrentValue()

建立可 BitmapImage 修改的物件克隆,並製作該物件當前值的深度複製。 資源參考、資料綁定和動畫不會被複製,但它們的當前值會被複製。

CloneCurrentValueCore(Freezable)

讓這個實例成為可修改的深度複製 BitmapSource 品,使用目前的屬性值。 資源參考、資料綁定和動畫不會被複製,但它們的當前值會被複製。

(繼承來源 BitmapSource)
CoerceValue(DependencyProperty)

強制設定指定的依賴性質值。 這是透過在屬性CoerceValueCallback中指定的依賴屬性元資料中,呼叫 的依賴屬性中的任何DependencyObject函式來達成的。

(繼承來源 DependencyObject)
CopyPixels(Array, Int32, Int32)

將點陣圖像素資料複製到像素陣列中,步幅為指定的偏移量。

(繼承來源 BitmapSource)
CopyPixels(Int32Rect, Array, Int32, Int32)

將指定矩形內的點陣圖像素資料複製到像素陣列中,該陣列的步幅從指定的偏移開始。

(繼承來源 BitmapSource)
CopyPixels(Int32Rect, IntPtr, Int32, Int32)

在指定的矩形內複製點陣圖像素資料。

(繼承來源 BitmapSource)
CreateInstance()

初始化 Freezable 類別的新執行個體。

(繼承來源 Freezable)
CreateInstanceCore()

當在導出類別中實作時,會建立該 Freezable 衍生類別的新實例。

(繼承來源 Freezable)
EndInit()

表示初始化結束 BitmapImage

Equals(Object)

判斷所給的 DependencyObject 是否等同於電流 DependencyObject

(繼承來源 DependencyObject)
Freeze()

使目前物件無法修改,並將其 IsFrozen 屬性設為 true

(繼承來源 Freezable)
FreezeCore(Boolean)

使 的 BitmapSource 或 衍生類別成為不可變的。

(繼承來源 BitmapSource)
GetAnimationBaseValue(DependencyProperty)

回傳指定的 DependencyProperty非動畫值。

(繼承來源 Animatable)
GetAsFrozen()

使用基礎(非動畫)屬性值建立一個凍結的 Freezable。 由於複製是凍結的,任何凍結的子物件都會透過參考被複製。

(繼承來源 Freezable)
GetAsFrozenCore(Freezable)

讓這個實例成為指定 BitmapSource 物件的克隆。

(繼承來源 BitmapSource)
GetCurrentValueAsFrozen()

用目前屬性值建立一個凍結的副本 Freezable 。 由於複製是凍結的,任何凍結的子物件都會透過參考被複製。

(繼承來源 Freezable)
GetCurrentValueAsFrozenCore(Freezable)

使此實例成為指定 BitmapSource的凍結克隆。 資源參考、資料綁定和動畫不會被複製,但它們的當前值會被複製。

(繼承來源 BitmapSource)
GetHashCode()

會得到一個 DependencyObject雜湊碼。

(繼承來源 DependencyObject)
GetLocalValueEnumerator()

建立專門的枚舉器,用以判斷哪些相依屬性在局部 DependencyObject設定值。

(繼承來源 DependencyObject)
GetType()

取得目前實例的 Type

(繼承來源 Object)
GetValue(DependencyProperty)

回傳此實例 DependencyObject上依賴屬性的當前有效值。

(繼承來源 DependencyObject)
InvalidateProperty(DependencyProperty)

重新評估指定相依性質的有效值。

(繼承來源 DependencyObject)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
OnChanged()

當當前 Freezable 物件被修改時呼叫。

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

此成員支援 Windows Presentation Foundation(WPF)基礎架構,並非直接從您的程式碼中使用。

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

確保剛設定的資料成員建立 DependencyObjectType 適當的上下文指標。

(繼承來源 Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

DependencyObject寫 的OnPropertyChanged(DependencyPropertyChangedEventArgs)實作,也在回應類型中變動的依賴屬性Changed時呼叫任何Freezable處理器。

(繼承來源 Freezable)
ReadLocalValue(DependencyProperty)

回傳依賴屬性的局部值(若存在)。

(繼承來源 DependencyObject)
ReadPreamble()

確保存取 Freezable 的是有效的執行緒。 繼 Freezable 承者必須在任何讀取非相依屬性資料成員的資料 API 開頭呼叫此方法。

(繼承來源 Freezable)
SetCurrentValue(DependencyProperty, Object)

設定依賴屬性的值,且不改變其值來源。

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

設定依賴屬性的局部值,並由其依賴屬性識別碼指定。

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

設定只讀相依屬性的本地值,該值由 DependencyPropertyKey 相依屬性的識別碼指定。

(繼承來源 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

回傳一個值,指示序列化程序是否應該將所提供的相依屬性的值序列化。

(繼承來源 DependencyObject)
ToString()

根據當前文化建立此物件的字串表示。

(繼承來源 ImageSource)
ToString(IFormatProvider)

根據傳入的物件 IFormatProvider 建立字串表示。 如果提供者是 null,則使用 。CurrentCulture

(繼承來源 ImageSource)
VerifyAccess()

強制呼叫執行緒能存取此 DispatcherObject

(繼承來源 DispatcherObject)
WritePostscript()

提升 Changed 事件並 Freezable 調用其 OnChanged() 方法。 衍生於 的 Freezable 類別應在任何修改未儲存為相依屬性的類別成員的 API 結尾呼叫此方法。

(繼承來源 Freezable)
WritePreamble()

驗證 未 Freezable 被凍結,且存取時正從有效的執行緒上下文中存取。 Freezable 繼承者應在任何寫入非相依屬性資料成員的 API 開頭呼叫此方法。

(繼承來源 Freezable)

事件

名稱 Description
Changed

Freezable 它所包含的物件被修改時,會發生這種情況。

(繼承來源 Freezable)
DecodeFailed

當影像檔因檔案標頭損毀而無法載入時,會發生這種情況。

(繼承來源 BitmapSource)
DownloadCompleted

當點陣圖內容已經完全下載完畢時,會發生這種情況。

(繼承來源 BitmapSource)
DownloadFailed

當點陣圖內容下載失敗時會發生。

(繼承來源 BitmapSource)
DownloadProgress

當點陣圖內容的下載進度改變時,會發生這種情況。

(繼承來源 BitmapSource)

明確介面實作

名稱 Description
IFormattable.ToString(String, IFormatProvider)

使用指定的格式,格式化目前實例的值。

(繼承來源 ImageSource)

適用於

另請參閱