BitmapDecoder.Create 方法

定义

使用指定的 BitmapDecoderBitmapCreateOptions 创建 BitmapCacheOption

重载

Create(Stream, BitmapCreateOptions, BitmapCacheOption)

用指定的 BitmapDecoderStreamBitmapCreateOptions 创建 BitmapCacheOption

Create(Uri, BitmapCreateOptions, BitmapCacheOption)

用指定的 BitmapDecoderUriBitmapCreateOptions 创建 BitmapCacheOption

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy)

用指定的 BitmapDecoderUriBitmapCreateOptionsBitmapCacheOption 创建一个 RequestCachePolicy

Create(Stream, BitmapCreateOptions, BitmapCacheOption)

public:
 static System::Windows::Media::Imaging::BitmapDecoder ^ Create(System::IO::Stream ^ bitmapStream, System::Windows::Media::Imaging::BitmapCreateOptions createOptions, System::Windows::Media::Imaging::BitmapCacheOption cacheOption);
public static System.Windows.Media.Imaging.BitmapDecoder Create (System.IO.Stream bitmapStream, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption);
static member Create : System.IO.Stream * System.Windows.Media.Imaging.BitmapCreateOptions * System.Windows.Media.Imaging.BitmapCacheOption -> System.Windows.Media.Imaging.BitmapDecoder
Public Shared Function Create (bitmapStream As Stream, createOptions As BitmapCreateOptions, cacheOption As BitmapCacheOption) As BitmapDecoder

参数

bitmapStream
Stream

用于标识要解码的位图的文件流。

createOptions
BitmapCreateOptions

标识此解码器的 BitmapCreateOptions

cacheOption
BitmapCacheOption

标识此解码器的 BitmapCacheOption

返回

BitmapDecoder

一个 BitmapDecoder,根据 Stream,通过使用指定的 BitmapCreateOptionsBitmapCacheOption

示例

以下示例演示如何使用 Create 该方法为给定图像创建解码器。 图像的第一BitmapFrameImage个用作控件的源。

Stream imageStream = new FileStream("sampleImages/waterlilies.jpg",
   FileMode.Open, FileAccess.Read, FileShare.Read);

BitmapDecoder streamBitmap = BitmapDecoder.Create(
   imageStream, BitmapCreateOptions.None,
   BitmapCacheOption.Default);

// Create an image element;
Image streamImage = new Image();
streamImage.Width = 200;
// Set image source using the first frame.
streamImage.Source = streamBitmap.Frames[0];
Dim imageStream As FileStream = New FileStream("sampleImages/waterlilies.jpg", FileMode.Open, FileAccess.Read, FileShare.Read)

Dim streamBitmap As BitmapDecoder = BitmapDecoder.Create(imageStream, BitmapCreateOptions.None, BitmapCacheOption.Default)

' Create an image element;
Dim streamImage As New Image()
streamImage.Width = 200
' Set image source using the first frame.
streamImage.Source = streamBitmap.Frames(0)

注解

OnLoad如果要在创建解码器后关闭bitmapStream缓存选项,请使用缓存选项。 默认 OnDemand 缓存选项将保留对流的访问,直到需要位图,垃圾回收器将处理清理。

另请参阅

适用于

Create(Uri, BitmapCreateOptions, BitmapCacheOption)

用指定的 BitmapDecoderUriBitmapCreateOptions 创建 BitmapCacheOption

public:
 static System::Windows::Media::Imaging::BitmapDecoder ^ Create(Uri ^ bitmapUri, System::Windows::Media::Imaging::BitmapCreateOptions createOptions, System::Windows::Media::Imaging::BitmapCacheOption cacheOption);
public static System.Windows.Media.Imaging.BitmapDecoder Create (Uri bitmapUri, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption);
static member Create : Uri * System.Windows.Media.Imaging.BitmapCreateOptions * System.Windows.Media.Imaging.BitmapCacheOption -> System.Windows.Media.Imaging.BitmapDecoder
Public Shared Function Create (bitmapUri As Uri, createOptions As BitmapCreateOptions, cacheOption As BitmapCacheOption) As BitmapDecoder

参数

bitmapUri
Uri

要解码的位图的 Uri

createOptions
BitmapCreateOptions

标识此解码器的 BitmapCreateOptions

cacheOption
BitmapCacheOption

标识此解码器的 BitmapCacheOption

返回

BitmapDecoder

一个 BitmapDecoder,根据 Uri,通过使用指定的 BitmapCreateOptionsBitmapCacheOption

例外

bitmapUrinull

bitmapUri 指定的类 ID 为不支持的格式类型。

示例

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

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)

另请参阅

适用于

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy)

public:
 static System::Windows::Media::Imaging::BitmapDecoder ^ Create(Uri ^ bitmapUri, System::Windows::Media::Imaging::BitmapCreateOptions createOptions, System::Windows::Media::Imaging::BitmapCacheOption cacheOption, System::Net::Cache::RequestCachePolicy ^ uriCachePolicy);
public static System.Windows.Media.Imaging.BitmapDecoder Create (Uri bitmapUri, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption, System.Net.Cache.RequestCachePolicy uriCachePolicy);
static member Create : Uri * System.Windows.Media.Imaging.BitmapCreateOptions * System.Windows.Media.Imaging.BitmapCacheOption * System.Net.Cache.RequestCachePolicy -> System.Windows.Media.Imaging.BitmapDecoder
Public Shared Function Create (bitmapUri As Uri, createOptions As BitmapCreateOptions, cacheOption As BitmapCacheOption, uriCachePolicy As RequestCachePolicy) As BitmapDecoder

参数

bitmapUri
Uri

位图的位置,从该位置创建 BitmapDecoder

createOptions
BitmapCreateOptions

用于创建此 BitmapDecoder 的选项。

cacheOption
BitmapCacheOption

用于创建此 BitmapDecoder 的缓存选项。

uriCachePolicy
RequestCachePolicy

BitmapDecoder 的缓存要求。

返回

BitmapDecoder

一个 BitmapDecoder,根据 Uri,通过使用指定的 BitmapCreateOptionsBitmapCacheOptionRequestCachePolicy

注解

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy).NET Framework版本 3.5 中引入。

适用于