BitmapFrame 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表解碼器回傳並被編碼器接受的影像資料。
public ref class BitmapFrame abstract : System::Windows::Media::Imaging::BitmapSource, System::Windows::Markup::IUriContext
public abstract class BitmapFrame : System.Windows.Media.Imaging.BitmapSource, System.Windows.Markup.IUriContext
type BitmapFrame = class
inherit BitmapSource
interface IUriContext
Public MustInherit Class BitmapFrame
Inherits BitmapSource
Implements IUriContext
- 繼承
- 實作
範例
以下程式碼範例示範如何利用 BitmapFrame建立新的 BitmapSource 。
int width = 128;
int height = width;
int stride = width/8;
byte[] pixels = new byte[height*stride];
// Try creating a new image with a custom palette.
List<System.Windows.Media.Color> colors = new List<System.Windows.Media.Color>();
colors.Add(System.Windows.Media.Colors.Red);
colors.Add(System.Windows.Media.Colors.Blue);
colors.Add(System.Windows.Media.Colors.Green);
BitmapPalette myPalette = new BitmapPalette(colors);
// Creates a new empty image with the pre-defined palette
BitmapSource image = BitmapSource.Create(
width,
height,
96,
96,
PixelFormats.Indexed1,
myPalette,
pixels,
stride);
FileStream stream = new FileStream("empty.tif", FileMode.Create);
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
encoder.Frames.Add(BitmapFrame.Create(image));
MessageBox.Show(myPalette.Colors.Count.ToString());
encoder.Save(stream);
Dim width As Integer = 128
Dim height As Integer = width
Dim stride As Integer = CType(width / 8, Integer)
Dim pixels(height * stride) As Byte
' Try creating a new image with a custom palette.
Dim colors As New List(Of System.Windows.Media.Color)()
colors.Add(System.Windows.Media.Colors.Red)
colors.Add(System.Windows.Media.Colors.Blue)
colors.Add(System.Windows.Media.Colors.Green)
Dim myPalette As New BitmapPalette(colors)
' Creates a new empty image with the pre-defined palette
Dim image As BitmapSource = System.Windows.Media.Imaging.BitmapSource.Create(width, height, 96, 96, PixelFormats.Indexed1, myPalette, pixels, stride)
Dim stream As New FileStream("empty.tif", FileMode.Create)
Dim encoder As New TiffBitmapEncoder()
Dim myTextBlock As New TextBlock()
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString()
encoder.Frames.Add(BitmapFrame.Create(image))
MessageBox.Show(myPalette.Colors.Count.ToString())
encoder.Save(stream)
以下程式碼範例示範如何使用物件 BitmapFrame 開啟可攜式網路圖形(PNG)圖形並透過此 CreateInPlaceBitmapMetadataWriter 方法撰寫元資料。
Stream^ pngStream = gcnew FileStream("smiley.png", FileMode::Open, FileAccess::ReadWrite, FileShare::ReadWrite);
PngBitmapDecoder^ pngDecoder = gcnew PngBitmapDecoder(pngStream, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
BitmapFrame^ pngFrame = pngDecoder->Frames[0];
InPlaceBitmapMetadataWriter^ pngInplace = pngFrame->CreateInPlaceBitmapMetadataWriter();
if (pngInplace->TrySave())
{
pngInplace->SetQuery("/Text/Description", "Have a nice day.");
}
pngStream->Close();
Stream pngStream = new System.IO.FileStream("smiley.png", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
PngBitmapDecoder pngDecoder = new PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame pngFrame = pngDecoder.Frames[0];
InPlaceBitmapMetadataWriter pngInplace = pngFrame.CreateInPlaceBitmapMetadataWriter();
if (pngInplace.TrySave())
{ pngInplace.SetQuery("/Text/Description", "Have a nice day."); }
pngStream.Close();
Dim pngStream As New System.IO.FileStream("smiley.png", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim pngDecoder As New PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim pngFrame As BitmapFrame = pngDecoder.Frames(0)
Dim pngInplace As InPlaceBitmapMetadataWriter = pngFrame.CreateInPlaceBitmapMetadataWriter()
If pngInplace.TrySave() = True Then
pngInplace.SetQuery("/Text/Description", "Have a nice day.")
End If
pngStream.Close()
備註
BitmapFrame 提供額外功能,無法透過 BitmapSource 提供與 Thumbnail 特定影像框架相關的存取來定義。 BitmapFrame 同時也支援使用 Metadata 屬性或 CreateInPlaceBitmapMetadataWriter 方法來撰寫元資料資訊。
解碼器回傳的電 BitmapFrame 梯永遠被凍結。 如果你需要可修改的副本,必須先用該Clone方法製作BitmapFrame一份副本。
只有標籤影像檔案格式(TIFF)和圖形交換格式(GIF)格式的影像支援多幀。
建構函式
| 名稱 | Description |
|---|---|
| BitmapFrame() |
初始化 BitmapFrame 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| BaseUri |
當在派生類別中覆寫時,會獲得或設定一個代表當前上下文基底 Uri 的值。 |
| CanFreeze |
會得到一個值,表示該物件是否能被設定為不可修改。 (繼承來源 Freezable) |
| ColorContexts |
當在派生類別中覆寫時,會得到一組 ColorContext 與此 BitmapFrame相關聯的物件。 |
| Decoder |
當在導出類別中覆寫時,會得到與該實例 BitmapFrame相關的解碼器。 |
| 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 |
會得到一個值,表示內容是否 BitmapSource 正在下載中。 (繼承來源 BitmapSource) |
| IsFrozen |
會得到一個值,表示該物件目前是否可修改。 (繼承來源 Freezable) |
| IsSealed |
會獲得一個值,表示該實例目前是否封存(唯讀)。 (繼承來源 DependencyObject) |
| Metadata |
取得與此點陣圖影像相關的元資料。 (繼承來源 BitmapSource) |
| Palette |
如果有指定,會取得點陣圖的色彩調色盤。 (繼承來源 BitmapSource) |
| PixelHeight |
它會取得點陣圖的高度(像素單位)。 (繼承來源 BitmapSource) |
| PixelWidth |
會得到點陣圖的寬度(像素數)。 (繼承來源 BitmapSource) |
| Thumbnail |
當在衍生類別中覆寫時,會得到與此 BitmapFrame相關聯的縮圖圖像。 |
| Width |
以裝置獨立單位取得位圖寬度(每單位 1/96 英吋)。 (繼承來源 BitmapSource) |
方法
事件
| 名稱 | Description |
|---|---|
| Changed |
當 Freezable 它所包含的物件被修改時,會發生這種情況。 (繼承來源 Freezable) |
| DecodeFailed |
當影像檔因檔案標頭損毀而無法載入時,會發生這種情況。 (繼承來源 BitmapSource) |
| DownloadCompleted |
當點陣圖內容已經完全下載完畢時,會發生這種情況。 (繼承來源 BitmapSource) |
| DownloadFailed |
當點陣圖內容下載失敗時會發生。 (繼承來源 BitmapSource) |
| DownloadProgress |
當點陣圖內容的下載進度改變時,會發生這種情況。 (繼承來源 BitmapSource) |
明確介面實作
| 名稱 | Description |
|---|---|
| IFormattable.ToString(String, IFormatProvider) |
使用指定的格式,格式化目前實例的值。 (繼承來源 ImageSource) |