Editare

Partajați prin


BitmapDecoder.Create Method

Definition

Creates a BitmapDecoder by using the specified BitmapCreateOptions and BitmapCacheOption.

Overloads

Create(Stream, BitmapCreateOptions, BitmapCacheOption)

Creates a BitmapDecoder from a Stream by using the specified BitmapCreateOptions and BitmapCacheOption.

Create(Uri, BitmapCreateOptions, BitmapCacheOption)

Creates a BitmapDecoder from a Uri by using the specified BitmapCreateOptions and BitmapCacheOption.

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy)

Creates a BitmapDecoder from a Uri by using the specified BitmapCreateOptions, BitmapCacheOption and RequestCachePolicy.

Create(Stream, BitmapCreateOptions, BitmapCacheOption)

Creates a BitmapDecoder from a Stream by using the specified BitmapCreateOptions and 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

Parameters

bitmapStream
Stream

The file stream that identifies the bitmap to decode.

createOptions
BitmapCreateOptions

Identifies the BitmapCreateOptions for this decoder.

cacheOption
BitmapCacheOption

Identifies the BitmapCacheOption for this decoder.

Returns

A BitmapDecoder from a Stream by using the specified BitmapCreateOptions and BitmapCacheOption.

Examples

The following example demonstrates how to use the Create method to create a decoder for a given image. The first BitmapFrame of the image is used as the source of an Image control.

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)

Remarks

Use the OnLoad cache option if you wish to close the bitmapStream after the decoder is created. The default OnDemand cache option retains access to the stream until the bitmap is needed, and cleanup is handled by the garbage collector.

See also

Applies to

Create(Uri, BitmapCreateOptions, BitmapCacheOption)

Creates a BitmapDecoder from a Uri by using the specified BitmapCreateOptions and 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

Parameters

bitmapUri
Uri

The Uri of the bitmap to decode.

createOptions
BitmapCreateOptions

Identifies the BitmapCreateOptions for this decoder.

cacheOption
BitmapCacheOption

Identifies the BitmapCacheOption for this decoder.

Returns

A BitmapDecoder from a Uri by using the specified BitmapCreateOptions and BitmapCacheOption.

Exceptions

The bitmapUri is null.

The bitmapUri specifies a class ID of an unsupported format type.

Examples

The following example demonstrates how to use the Create(Uri, BitmapCreateOptions, BitmapCacheOption) method to create a decoder for a given image. The first BitmapFrame of the image is used as the source of an Image control.

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)

See also

Applies to

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy)

Creates a BitmapDecoder from a Uri by using the specified BitmapCreateOptions, BitmapCacheOption and 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

Parameters

bitmapUri
Uri

The location of the bitmap from which the BitmapDecoder is created.

createOptions
BitmapCreateOptions

The options that are used to create this BitmapDecoder.

cacheOption
BitmapCacheOption

The cache option that is used to create this BitmapDecoder.

uriCachePolicy
RequestCachePolicy

The caching requirements for this BitmapDecoder.

Returns

A BitmapDecoder from a Uri by using the specified BitmapCreateOptions, BitmapCacheOption and RequestCachePolicy.

Remarks

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy) is introduced in the .NET Framework version 3.5.

Applies to