BitmapFrame.Create BitmapFrame.Create BitmapFrame.Create BitmapFrame.Create Method

Definition

Creates a new BitmapFrame based on the supplied arguments.

Overloads

Create(Stream) Create(Stream) Create(Stream) Create(Stream)

Creates a new BitmapFrame from a given Stream.

Create(Uri) Create(Uri) Create(Uri) Create(Uri)

Creates a new BitmapFrame from a given Uri.

Create(BitmapSource) Create(BitmapSource) Create(BitmapSource) Create(BitmapSource)

Creates a new BitmapFrame from a given BitmapSource.

Create(Uri, RequestCachePolicy) Create(Uri, RequestCachePolicy) Create(Uri, RequestCachePolicy) Create(Uri, RequestCachePolicy)

Creates a BitmapFrame from a given Uri with the specified RequestCachePolicy.

Create(BitmapSource, BitmapSource) Create(BitmapSource, BitmapSource) Create(BitmapSource, BitmapSource) Create(BitmapSource, BitmapSource)

Creates a new BitmapFrame from a given BitmapSource with the specified thumbnail.

Create(Stream, BitmapCreateOptions, BitmapCacheOption) Create(Stream, BitmapCreateOptions, BitmapCacheOption) Create(Stream, BitmapCreateOptions, BitmapCacheOption) Create(Stream, BitmapCreateOptions, BitmapCacheOption)

Creates a new BitmapFrame from a given Stream with the specified BitmapCreateOptions and BitmapCacheOption.

Create(Uri, BitmapCreateOptions, BitmapCacheOption) Create(Uri, BitmapCreateOptions, BitmapCacheOption) Create(Uri, BitmapCreateOptions, BitmapCacheOption) Create(Uri, BitmapCreateOptions, BitmapCacheOption)

Creates a BitmapFrame from a given Uri with the specified BitmapCreateOptions and BitmapCacheOption.

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy) Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy) Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy) Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy)

Creates a BitmapFrame from a given Uri with the specified BitmapCreateOptions, BitmapCacheOption, and RequestCachePolicy.

Create(BitmapSource, BitmapSource, BitmapMetadata, ReadOnlyCollection<ColorContext>) Create(BitmapSource, BitmapSource, BitmapMetadata, ReadOnlyCollection<ColorContext>) Create(BitmapSource, BitmapSource, BitmapMetadata, ReadOnlyCollection<ColorContext>) Create(BitmapSource, BitmapSource, BitmapMetadata, ReadOnlyCollection<ColorContext>)

Creates a new BitmapFrame from a given BitmapSource with the specified thumbnail, BitmapMetadata, and ColorContext.

Create(Stream) Create(Stream) Create(Stream) Create(Stream)

Creates a new BitmapFrame from a given Stream.

public:
 static System::Windows::Media::Imaging::BitmapFrame ^ Create(System::IO::Stream ^ bitmapStream);
public static System.Windows.Media.Imaging.BitmapFrame Create (System.IO.Stream bitmapStream);
static member Create : System.IO.Stream -> System.Windows.Media.Imaging.BitmapFrame
Public Shared Function Create (bitmapStream As Stream) As BitmapFrame

Parameters

bitmapStream
Stream Stream Stream Stream

The Stream that is used to construct the BitmapFrame.

Returns

Remarks

The bitmapStream can be closed after the frame is created only when the OnLoad cache option is used. The default OnDemand cache option retains the stream until the frame is needed. Use the Create(Stream, BitmapCreateOptions, BitmapCacheOption) method to specify create and cache options.

Create(Uri) Create(Uri) Create(Uri) Create(Uri)

Creates a new BitmapFrame from a given Uri.

public:
 static System::Windows::Media::Imaging::BitmapFrame ^ Create(Uri ^ bitmapUri);
public static System.Windows.Media.Imaging.BitmapFrame Create (Uri bitmapUri);
static member Create : Uri -> System.Windows.Media.Imaging.BitmapFrame
Public Shared Function Create (bitmapUri As Uri) As BitmapFrame

Parameters

bitmapUri
Uri Uri Uri Uri

The Uri that identifies the source of the BitmapFrame.

Returns

Examples

The following code example demonstrates how to construct a BitmapFrame from a given Uri.

int width = 128;
int height = width;
int stride = width/8;
byte[] pixels = new byte[height*stride];

// Try creating a new image with a custom palette.
List<System.Windows.Media.Color> colors = new List<System.Windows.Media.Color>();
colors.Add(System.Windows.Media.Colors.Red);
colors.Add(System.Windows.Media.Colors.Blue);
colors.Add(System.Windows.Media.Colors.Green);
BitmapPalette myPalette = new BitmapPalette(colors);

// Creates a new empty image with the pre-defined palette

BitmapSource image = BitmapSource.Create(
    width,
    height,
    96,
    96,
    PixelFormats.Indexed1,
    myPalette, 
    pixels, 
    stride);

FileStream stream = new FileStream("empty.tif", FileMode.Create);
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString();
encoder.Frames.Add(BitmapFrame.Create(image));
MessageBox.Show(myPalette.Colors.Count.ToString());
encoder.Save(stream);

Dim width As Integer = 128
Dim height As Integer = width
Dim stride As Integer = CType(width / 8, Integer)
Dim pixels(height * stride) As Byte

' Try creating a new image with a custom palette.
Dim colors As New List(Of System.Windows.Media.Color)()
colors.Add(System.Windows.Media.Colors.Red)
colors.Add(System.Windows.Media.Colors.Blue)
colors.Add(System.Windows.Media.Colors.Green)
Dim myPalette As New BitmapPalette(colors)

' Creates a new empty image with the pre-defined palette
Dim image As BitmapSource = System.Windows.Media.Imaging.BitmapSource.Create(width, height, 96, 96, PixelFormats.Indexed1, myPalette, pixels, stride)
Dim stream As New FileStream("empty.tif", FileMode.Create)
Dim encoder As New TiffBitmapEncoder()
Dim myTextBlock As New TextBlock()
myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString()
encoder.Frames.Add(BitmapFrame.Create(image))
MessageBox.Show(myPalette.Colors.Count.ToString())
encoder.Save(stream)

Create(BitmapSource) Create(BitmapSource) Create(BitmapSource) Create(BitmapSource)

Creates a new BitmapFrame from a given BitmapSource.

public:
 static System::Windows::Media::Imaging::BitmapFrame ^ Create(System::Windows::Media::Imaging::BitmapSource ^ source);
public static System.Windows.Media.Imaging.BitmapFrame Create (System.Windows.Media.Imaging.BitmapSource source);
static member Create : System.Windows.Media.Imaging.BitmapSource -> System.Windows.Media.Imaging.BitmapFrame
Public Shared Function Create (source As BitmapSource) As BitmapFrame

Parameters

source
BitmapSource BitmapSource BitmapSource BitmapSource

The BitmapSource that is used to construct this BitmapFrame.

Returns

Create(Uri, RequestCachePolicy) Create(Uri, RequestCachePolicy) Create(Uri, RequestCachePolicy) Create(Uri, RequestCachePolicy)

Creates a BitmapFrame from a given Uri with the specified RequestCachePolicy.

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

Parameters

bitmapUri
Uri Uri Uri Uri

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

uriCachePolicy
RequestCachePolicy RequestCachePolicy RequestCachePolicy RequestCachePolicy

The caching requirements for this BitmapFrame.

Returns

Remarks

Create(Uri, RequestCachePolicy) is introduced in the .NET Framework version 3.5. For more information, see Versions and Dependencies.

Create(BitmapSource, BitmapSource) Create(BitmapSource, BitmapSource) Create(BitmapSource, BitmapSource) Create(BitmapSource, BitmapSource)

Creates a new BitmapFrame from a given BitmapSource with the specified thumbnail.

public:
 static System::Windows::Media::Imaging::BitmapFrame ^ Create(System::Windows::Media::Imaging::BitmapSource ^ source, System::Windows::Media::Imaging::BitmapSource ^ thumbnail);
public static System.Windows.Media.Imaging.BitmapFrame Create (System.Windows.Media.Imaging.BitmapSource source, System.Windows.Media.Imaging.BitmapSource thumbnail);
static member Create : System.Windows.Media.Imaging.BitmapSource * System.Windows.Media.Imaging.BitmapSource -> System.Windows.Media.Imaging.BitmapFrame
Public Shared Function Create (source As BitmapSource, thumbnail As BitmapSource) As BitmapFrame

Parameters

source
BitmapSource BitmapSource BitmapSource BitmapSource

The source from which the BitmapFrame is constructed.

thumbnail
BitmapSource BitmapSource BitmapSource BitmapSource

A thumbnail image of the resulting BitmapFrame.

Returns

A BitmapFrame from a given BitmapSource with the specified thumbnail.

Create(Stream, BitmapCreateOptions, BitmapCacheOption) Create(Stream, BitmapCreateOptions, BitmapCacheOption) Create(Stream, BitmapCreateOptions, BitmapCacheOption) Create(Stream, BitmapCreateOptions, BitmapCacheOption)

Creates a new BitmapFrame from a given Stream with the specified BitmapCreateOptions and BitmapCacheOption.

public:
 static System::Windows::Media::Imaging::BitmapFrame ^ Create(System::IO::Stream ^ bitmapStream, System::Windows::Media::Imaging::BitmapCreateOptions createOptions, System::Windows::Media::Imaging::BitmapCacheOption cacheOption);
public static System.Windows.Media.Imaging.BitmapFrame 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.BitmapFrame
Public Shared Function Create (bitmapStream As Stream, createOptions As BitmapCreateOptions, cacheOption As BitmapCacheOption) As BitmapFrame

Parameters

bitmapStream
Stream Stream Stream Stream

The stream from which this BitmapFrame is constructed.

createOptions
BitmapCreateOptions BitmapCreateOptions BitmapCreateOptions BitmapCreateOptions

The options that are used to create this BitmapFrame.

cacheOption
BitmapCacheOption BitmapCacheOption BitmapCacheOption BitmapCacheOption

The cache option that is used to create this BitmapFrame.

Returns

Remarks

Use the OnLoad cache option if you wish to close the bitmapStream after the bitmap 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.

Create(Uri, BitmapCreateOptions, BitmapCacheOption) Create(Uri, BitmapCreateOptions, BitmapCacheOption) Create(Uri, BitmapCreateOptions, BitmapCacheOption) Create(Uri, BitmapCreateOptions, BitmapCacheOption)

Creates a BitmapFrame from a given Uri with the specified BitmapCreateOptions and BitmapCacheOption.

public:
 static System::Windows::Media::Imaging::BitmapFrame ^ Create(Uri ^ bitmapUri, System::Windows::Media::Imaging::BitmapCreateOptions createOptions, System::Windows::Media::Imaging::BitmapCacheOption cacheOption);
public static System.Windows.Media.Imaging.BitmapFrame 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.BitmapFrame
Public Shared Function Create (bitmapUri As Uri, createOptions As BitmapCreateOptions, cacheOption As BitmapCacheOption) As BitmapFrame

Parameters

bitmapUri
Uri Uri Uri Uri

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

createOptions
BitmapCreateOptions BitmapCreateOptions BitmapCreateOptions BitmapCreateOptions

The options that are used to create this BitmapFrame.

cacheOption
BitmapCacheOption BitmapCacheOption BitmapCacheOption BitmapCacheOption

The cache option that is used to create this BitmapFrame.

Returns

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy) Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy) Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy) Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy)

Creates a BitmapFrame from a given Uri with the specified BitmapCreateOptions, BitmapCacheOption, and RequestCachePolicy.

public:
 static System::Windows::Media::Imaging::BitmapFrame ^ 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.BitmapFrame 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.BitmapFrame
Public Shared Function Create (bitmapUri As Uri, createOptions As BitmapCreateOptions, cacheOption As BitmapCacheOption, uriCachePolicy As RequestCachePolicy) As BitmapFrame

Parameters

bitmapUri
Uri Uri Uri Uri

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

createOptions
BitmapCreateOptions BitmapCreateOptions BitmapCreateOptions BitmapCreateOptions

The options that are used to create this BitmapFrame.

cacheOption
BitmapCacheOption BitmapCacheOption BitmapCacheOption BitmapCacheOption

The cache option that is used to create this BitmapFrame.

uriCachePolicy
RequestCachePolicy RequestCachePolicy RequestCachePolicy RequestCachePolicy

The caching requirements for this BitmapFrame.

Returns

Remarks

Create(Uri, BitmapCreateOptions, BitmapCacheOption, RequestCachePolicy) is introduced in the .NET Framework version 3.5. For more information, see Versions and Dependencies.

Create(BitmapSource, BitmapSource, BitmapMetadata, ReadOnlyCollection<ColorContext>) Create(BitmapSource, BitmapSource, BitmapMetadata, ReadOnlyCollection<ColorContext>) Create(BitmapSource, BitmapSource, BitmapMetadata, ReadOnlyCollection<ColorContext>) Create(BitmapSource, BitmapSource, BitmapMetadata, ReadOnlyCollection<ColorContext>)

Creates a new BitmapFrame from a given BitmapSource with the specified thumbnail, BitmapMetadata, and ColorContext.

public:
 static System::Windows::Media::Imaging::BitmapFrame ^ Create(System::Windows::Media::Imaging::BitmapSource ^ source, System::Windows::Media::Imaging::BitmapSource ^ thumbnail, System::Windows::Media::Imaging::BitmapMetadata ^ metadata, System::Collections::ObjectModel::ReadOnlyCollection<System::Windows::Media::ColorContext ^> ^ colorContexts);
public static System.Windows.Media.Imaging.BitmapFrame Create (System.Windows.Media.Imaging.BitmapSource source, System.Windows.Media.Imaging.BitmapSource thumbnail, System.Windows.Media.Imaging.BitmapMetadata metadata, System.Collections.ObjectModel.ReadOnlyCollection<System.Windows.Media.ColorContext> colorContexts);
static member Create : System.Windows.Media.Imaging.BitmapSource * System.Windows.Media.Imaging.BitmapSource * System.Windows.Media.Imaging.BitmapMetadata * System.Collections.ObjectModel.ReadOnlyCollection<System.Windows.Media.ColorContext> -> System.Windows.Media.Imaging.BitmapFrame
Public Shared Function Create (source As BitmapSource, thumbnail As BitmapSource, metadata As BitmapMetadata, colorContexts As ReadOnlyCollection(Of ColorContext)) As BitmapFrame

Parameters

source
BitmapSource BitmapSource BitmapSource BitmapSource

The BitmapSource that is used to construct this BitmapFrame.

thumbnail
BitmapSource BitmapSource BitmapSource BitmapSource

A thumbnail image of the resulting BitmapFrame.

metadata
BitmapMetadata BitmapMetadata BitmapMetadata BitmapMetadata

The metadata to associate with this BitmapFrame.

colorContexts
ReadOnlyCollection<ColorContext>

The ColorContext objects that are associated with this BitmapFrame.

Returns

Applies to