PngBitmapDecoder 构造函数

定义

初始化 PngBitmapDecoder 的新实例。

重载

PngBitmapDecoder(Stream, BitmapCreateOptions, BitmapCacheOption)

从指定的文件流,用指定的 createOptionscacheOption 初始化 PngBitmapDecoder 类的一个新实例。

PngBitmapDecoder(Uri, BitmapCreateOptions, BitmapCacheOption)

从指定的 PngBitmapDecoder,用指定的 createOptionscacheOption 初始化 Uri 的一个新实例。

PngBitmapDecoder(Stream, BitmapCreateOptions, BitmapCacheOption)

从指定的文件流,用指定的 createOptionscacheOption 初始化 PngBitmapDecoder 类的一个新实例。

public:
 PngBitmapDecoder(System::IO::Stream ^ bitmapStream, System::Windows::Media::Imaging::BitmapCreateOptions createOptions, System::Windows::Media::Imaging::BitmapCacheOption cacheOption);
[System.Security.SecurityCritical]
public PngBitmapDecoder (System.IO.Stream bitmapStream, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption);
public PngBitmapDecoder (System.IO.Stream bitmapStream, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption);
[<System.Security.SecurityCritical>]
new System.Windows.Media.Imaging.PngBitmapDecoder : System.IO.Stream * System.Windows.Media.Imaging.BitmapCreateOptions * System.Windows.Media.Imaging.BitmapCacheOption -> System.Windows.Media.Imaging.PngBitmapDecoder
new System.Windows.Media.Imaging.PngBitmapDecoder : System.IO.Stream * System.Windows.Media.Imaging.BitmapCreateOptions * System.Windows.Media.Imaging.BitmapCacheOption -> System.Windows.Media.Imaging.PngBitmapDecoder
Public Sub New (bitmapStream As Stream, createOptions As BitmapCreateOptions, cacheOption As BitmapCacheOption)

参数

bitmapStream
Stream

要解码的位图流。

createOptions
BitmapCreateOptions

位图图像的初始化选项。

cacheOption
BitmapCacheOption

用于位图图像的缓存方法。

属性

例外

bitmapStream 值为 null

bitmapStream不是可移植网络图形 (PNG) 编码图像。

示例

下面的代码示例演示如何从文件流创建和使用 PngBitmapDecoder 实例。 解码的图像用作控件的 Image 源。


// Open a Stream and decode a PNG image
Stream^ imageStreamSource = gcnew FileStream("smiley.png", FileMode::Open, FileAccess::Read, FileShare::Read);
PngBitmapDecoder^ decoder = gcnew PngBitmapDecoder(imageStreamSource, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
BitmapSource^ bitmapSource = decoder->Frames[0];

// Draw the Image
Image^ myImage = gcnew Image();
myImage->Source = bitmapSource;
myImage->Stretch = Stretch::None;
myImage->Margin = System::Windows::Thickness(20);

// Open a Stream and decode a PNG image
Stream imageStreamSource = new FileStream("smiley.png", FileMode.Open, FileAccess.Read, FileShare.Read);
PngBitmapDecoder decoder = new PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource = decoder.Frames[0];

// Draw the Image
Image myImage = new Image();
myImage.Source = bitmapSource;
myImage.Stretch = Stretch.None;
myImage.Margin = new Thickness(20);
' Open a Stream and decode a PNG image
Dim imageStreamSource As New FileStream("smiley.png", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim decoder As New PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim bitmapSource As BitmapSource = decoder.Frames(0)

' Draw the Image
Dim myImage As New Image()
myImage.Source = bitmapSource
myImage.Stretch = Stretch.None
myImage.Margin = New Thickness(20)

注解

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

适用于

PngBitmapDecoder(Uri, BitmapCreateOptions, BitmapCacheOption)

从指定的 PngBitmapDecoder,用指定的 createOptionscacheOption 初始化 Uri 的一个新实例。

public:
 PngBitmapDecoder(Uri ^ bitmapUri, System::Windows::Media::Imaging::BitmapCreateOptions createOptions, System::Windows::Media::Imaging::BitmapCacheOption cacheOption);
[System.Security.SecurityCritical]
public PngBitmapDecoder (Uri bitmapUri, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption);
public PngBitmapDecoder (Uri bitmapUri, System.Windows.Media.Imaging.BitmapCreateOptions createOptions, System.Windows.Media.Imaging.BitmapCacheOption cacheOption);
[<System.Security.SecurityCritical>]
new System.Windows.Media.Imaging.PngBitmapDecoder : Uri * System.Windows.Media.Imaging.BitmapCreateOptions * System.Windows.Media.Imaging.BitmapCacheOption -> System.Windows.Media.Imaging.PngBitmapDecoder
new System.Windows.Media.Imaging.PngBitmapDecoder : Uri * System.Windows.Media.Imaging.BitmapCreateOptions * System.Windows.Media.Imaging.BitmapCacheOption -> System.Windows.Media.Imaging.PngBitmapDecoder
Public Sub New (bitmapUri As Uri, createOptions As BitmapCreateOptions, cacheOption As BitmapCacheOption)

参数

bitmapUri
Uri

Uri 用于标识要解码的位图。

createOptions
BitmapCreateOptions

位图图像的初始化选项。

cacheOption
BitmapCacheOption

用于位图图像的缓存方法。

属性

例外

bitmapUri 值为 null

bitmapUri不是可移植网络图形 (PNG) 编码图像。

示例

下面的代码示例演示如何创建实例并使用 PngBitmapDecoder a Uri. 解码的图像用作控件的 Image 源。


// Open a Uri and decode a PNG image
System::Uri^ myUri = gcnew System::Uri("smiley.png", UriKind::RelativeOrAbsolute);
PngBitmapDecoder^ decoder2 = gcnew PngBitmapDecoder(myUri, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
BitmapSource^ bitmapSource2 = decoder2->Frames[0];

// Draw the Image
Image^ myImage2 = gcnew Image();
myImage2->Source = bitmapSource2;
myImage2->Stretch = Stretch::None;
myImage2->Margin = System::Windows::Thickness(20);

// Open a Uri and decode a PNG image
Uri myUri = new Uri("smiley.png", UriKind.RelativeOrAbsolute);
PngBitmapDecoder decoder2 = new PngBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapSource bitmapSource2 = decoder2.Frames[0];

// Draw the Image
Image myImage2 = new Image();
myImage2.Source = bitmapSource2;
myImage2.Stretch = Stretch.None;
myImage2.Margin = new Thickness(20);
' Open a Uri and decode a PNG image
Dim myUri As New Uri("smiley.png", UriKind.RelativeOrAbsolute)
Dim decoder2 As New PngBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim bitmapSource2 As BitmapSource = decoder2.Frames(0)

' Draw the Image
Dim myImage2 As New Image()
myImage2.Source = bitmapSource2
myImage2.Stretch = Stretch.None
myImage2.Margin = New Thickness(20)

适用于