BitmapImage 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供一種專門化的程式 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 |
|---|---|
| Changed |
當 Freezable 它所包含的物件被修改時,會發生這種情況。 (繼承來源 Freezable) |
| DecodeFailed |
當影像檔因檔案標頭損毀而無法載入時,會發生這種情況。 (繼承來源 BitmapSource) |
| DownloadCompleted |
當點陣圖內容已經完全下載完畢時,會發生這種情況。 (繼承來源 BitmapSource) |
| DownloadFailed |
當點陣圖內容下載失敗時會發生。 (繼承來源 BitmapSource) |
| DownloadProgress |
當點陣圖內容的下載進度改變時,會發生這種情況。 (繼承來源 BitmapSource) |
明確介面實作
| 名稱 | Description |
|---|---|
| IFormattable.ToString(String, IFormatProvider) |
使用指定的格式,格式化目前實例的值。 (繼承來源 ImageSource) |