BitmapDecoder 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供对位图容器数据以及第一个帧中的数据的读取访问权限。
public ref class BitmapDecoder sealed : IBitmapFrameWithSoftwareBitmap
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class BitmapDecoder final : IBitmapFrameWithSoftwareBitmap
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class BitmapDecoder : IBitmapFrameWithSoftwareBitmap
Public NotInheritable Class BitmapDecoder
Implements IBitmapFrameWithSoftwareBitmap
- 继承
- 属性
- 实现
Windows 要求
| 设备系列 |
Windows 10 (在 10.0.10240.0 中引入)
|
| API contract |
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
|
示例
下面是创建解码器对象的部分示例。 此示例假定你选择了 Windows.Storage.Pickers.FileOpenPicker 的文件。 有关选择文件、创建解码器和解码图像的完整说明,请参阅 图像处理
FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileOpenPicker.FileTypeFilter.Add(".jpg");
fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
var inputFile = await fileOpenPicker.PickSingleFileAsync();
if (inputFile == null)
{
// The user cancelled the picking operation
return;
}
SoftwareBitmap softwareBitmap;
using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
{
// Create the decoder from the stream
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
// Get the SoftwareBitmap representation of the file
softwareBitmap = await decoder.GetSoftwareBitmapAsync();
}
注解
图像格式
BitmapDecoder 可以解码以下格式。
- JPEG
- PNG
- GIF
- TIFF
- BMP
- ICO
- JPEG-XR
- 使用 Microsoft 相机编解码器包安装的任何相机原始格式。
有关解码格式的列表,请参阅 BitmapEncoder 主题。
BitmapDecoder 类实现 IBitmapFrame。 它提供对容器数据以及来自第一个帧的数据的访问。 这使应用程序无需检索单独的 BitmapFrame 即可完成最常见的方案。
版本历史记录
| Windows 版本 | SDK 版本 | 增值 |
|---|---|---|
| 1809 | 17763 | HeifDecoderId |
| 1809 | 17763 | WebpDecoderId |
属性
| BitmapAlphaMode |
第一帧的默认 alpha 模式。 |
| BitmapContainerProperties |
提供对容器位图属性的访问。 |
| BitmapPixelFormat |
最适合第一帧的像素格式。 |
| BitmapProperties |
第一个帧中元数据的只读视图。 |
| BmpDecoderId |
BMP 解码器的唯一标识符。 |
| DecoderInformation |
有关位图解码器的信息。 |
| DpiX |
第一帧的水平分辨率(以点/英寸为单位)。 |
| DpiY |
第一帧的垂直分辨率(以点/英寸为单位)。 |
| FrameCount |
图像文件中的帧数。 |
| GifDecoderId |
GIF 解码器的唯一标识符。 |
| HeifDecoderId |
HEIF 解码器的唯一标识符。 |
| IcoDecoderId |
ICO 解码器的唯一标识符。 |
| JpegDecoderId |
JPEG 解码器的唯一标识符。 |
| JpegXRDecoderId |
JPEG-XR 解码器的唯一标识符。 |
| OrientedPixelHeight |
将任何 EXIF 方向应用于位图后,第一帧的高度(以像素为单位)。 |
| OrientedPixelWidth |
将任何 EXIF 方向应用于位图后,第一个帧的宽度(以像素为单位)。 |
| PixelHeight |
第一个帧的高度(以像素为单位)。 |
| PixelWidth |
第一个帧的宽度(以像素为单位)。 |
| PngDecoderId |
PNG 解码器的唯一标识符。 |
| TiffDecoderId |
TIFF 解码器的唯一标识符。 |
| WebpDecoderId |
WebP 解码器的唯一标识符。 |
方法
| CreateAsync(Guid, IRandomAccessStream) |
使用特定位图编解码器异步创建新的 BitmapDecoder ,并使用流初始化它。 |
| CreateAsync(IRandomAccessStream) |
异步创建新的 BitmapDecoder 并使用流对其进行初始化。 |
| GetDecoderInformationEnumerator() |
安装在系统上的位图解码器及其相关信息。 |
| GetFrameAsync(UInt32) |
从图像文件中异步检索帧。 |
| GetPixelDataAsync() |
异步请求帧的像素数据。 |
| GetPixelDataAsync(BitmapPixelFormat, BitmapAlphaMode, BitmapTransform, ExifOrientationMode, ColorManagementMode) |
使用指定的参数异步请求帧的像素数据。 |
| GetPreviewAsync() |
异步返回包含预览图像的流。 |
| GetSoftwareBitmapAsync() |
异步获取解码的位图的 SoftwareBitmap 表示形式。 |
| GetSoftwareBitmapAsync(BitmapPixelFormat, BitmapAlphaMode, BitmapTransform, ExifOrientationMode, ColorManagementMode) |
异步获取解码的位图的 SoftwareBitmap 表示形式。 |
| GetSoftwareBitmapAsync(BitmapPixelFormat, BitmapAlphaMode) |
异步获取解码的位图的 SoftwareBitmap 表示形式。 |
| GetThumbnailAsync() |
异步返回包含缩略图的流。 |