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.

C#
public static System.Windows.Media.Imaging.BitmapDecoder Create(System.IO.Stream bitmapStream, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption);

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.

C#
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];

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Create(Uri, BitmapCreateOptions, BitmapCacheOption)

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

C#
public static System.Windows.Media.Imaging.BitmapDecoder Create(Uri bitmapUri, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption);

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.

C#
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];

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy)

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

C#
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);

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

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10