BitmapDecoder 类

定义

表示位图帧的容器。 每个位图帧都是一个 BitmapSource。 此抽象类为所有派生解码器对象提供一组基本功能。

public ref class BitmapDecoder abstract : System::Windows::Threading::DispatcherObject
public abstract class BitmapDecoder : System.Windows.Threading.DispatcherObject
type BitmapDecoder = class
    inherit DispatcherObject
Public MustInherit Class BitmapDecoder
Inherits DispatcherObject
继承
BitmapDecoder
派生

示例

以下示例演示如何使用 Create(Uri, BitmapCreateOptions, BitmapCacheOption) 该方法为给定图像创建解码器。 第一 BitmapFrame 个图像用作控件的 Image 源。

BitmapDecoder uriBitmap = BitmapDecoder.Create(
   new Uri("sampleImages/waterlilies.jpg", UriKind.Relative),
   BitmapCreateOptions.None,
   BitmapCacheOption.Default);

// Create an image element;
Image uriImage = new Image();
uriImage.Width = 200;
// Set image source.
uriImage.Source = uriBitmap.Frames[0];
Dim uriBitmap As BitmapDecoder = BitmapDecoder.Create(New Uri("sampleImages/waterlilies.jpg", UriKind.Relative), BitmapCreateOptions.None, BitmapCacheOption.Default)

' Create an image element;
Dim uriImage As New Image()
uriImage.Width = 200
' Set image source.
uriImage.Source = uriBitmap.Frames(0)

下面的代码示例演示如何使用内置 TiffBitmapDecoder 代码打开和解码标记图像文件格式 (TIFF) 位图。 生成的BitmapSource结果用作SourceImage元素。


// Open a Stream and decode a TIFF image
Stream imageStreamSource = new FileStream("tulipfarm.tif", FileMode.Open, FileAccess.Read, FileShare.Read);
TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];

// Draw the Image
Image myImage1 = new Image();
myImage1.Source = bitmapSource;
myImage1.Stretch = Stretch.None;
myImage1.Margin = new Thickness(20);
' Open a Stream and decode a TIFF image
Dim imageStreamSource As New FileStream("tulipfarm.tif", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim decoder As New TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim bitmapSource As BitmapSource = decoder.Frames(0)

' Draw the Image
Dim myImage1 As New Image()
myImage1.Source = bitmapSource
myImage1.Stretch = Stretch.None
myImage1.Margin = New Thickness(20)

注解

BitmapDecoder 不是本身 BitmapFrame ;而是对象的 BitmapFrame 容器。 BitmapFrame容器中的每个属性可能具有不同的属性,包括不同的大小、分辨率或调色板。

除非选择了特定的编解码器,否则Windows Presentation Foundation(WPF)使用自动运行时发现来标识图像的格式,并将其与相应的编解码器匹配。 此发现过程允许由独立软件供应商(ISV)开发的编解码器由系统自动发现。 若要选择特定的编解码器,应使用派生 BitmapDecoderBitmapEncoder类等 TiffBitmapDecoder

标记的图像文件格式(TIFF)和图形交换格式(GIF)是唯一支持多个帧的图像格式。

构造函数

名称 说明
BitmapDecoder()

初始化 的新 BitmapDecoder实例。

属性

名称 说明
CodecInfo

获取描述此编解码器的信息。

ColorContexts

获取一个值,该值表示与位图关联的颜色配置文件(如果已定义)。

Dispatcher

获取与此DispatcherDispatcherObject关联的值。

(继承自 DispatcherObject)
Frames

获取位图中单个帧的内容。

IsDownloading

获取一个值,该值指示解码器当前是否正在下载内容。

Metadata

获取表示与此位图关联的全局元数据(如果定义了元数据)的实例 BitmapMetadata

Palette

获取 BitmapPalette 与此解码器关联的值。

Preview

获取一个 BitmapSource 表示此位图的全局预览(如果已定义)。

Thumbnail

获取一个 BitmapSource 表示位图的缩略图(如果定义了位图)。

方法

名称 说明
CheckAccess()

确定调用线程是否有权访问此 DispatcherObject权限。

(继承自 DispatcherObject)
Create(Stream, BitmapCreateOptions, BitmapCacheOption)

BitmapDecoder Stream使用指定的BitmapCreateOptionsBitmapCacheOption.

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy)

使用指定的 a; 从 a 创建一个

Create(Uri, BitmapCreateOptions, BitmapCacheOption)

BitmapDecoder Uri使用指定的BitmapCreateOptionsBitmapCacheOption.

CreateInPlaceBitmapMetadataWriter()

创建可用于更新位图元数据的实例 InPlaceBitmapMetadataWriter

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
Finalize()

在垃圾回收回收之前 BitmapDecoder 释放资源并执行其他清理操作。

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

将 a BitmapDecoder 的当前值转换为 .String

VerifyAccess()

强制调用线程有权访问此 DispatcherObject权限。

(继承自 DispatcherObject)

活动

名称 说明
DownloadCompleted

下载完位图内容后 BitmapDecoder 发生。

DownloadFailed

当位图内容无法下载时发生。

DownloadProgress

BitmapDecoder在正在下载位图内容时发生。

适用于

另请参阅