BitmapDecoder.Create 方法

定义

重载

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 Stream使用指定的BitmapCreateOptionsBitmapCacheOption.

示例

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

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)

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 Uri使用指定的BitmapCreateOptionsBitmapCacheOption.

例外

bitmapUrinull

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

示例

以下示例演示如何使用 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)

另请参阅

适用于

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy)

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

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 Uri使用指定的BitmapCreateOptionsBitmapCacheOptionRequestCachePolicy.

注解

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

适用于