BitmapImage.DecodePixelWidth 属性

定义

获取或设置图像解码后的宽度(以像素为单位)。

public:
 property int DecodePixelWidth { int get(); void set(int value); };
public int DecodePixelWidth { get; set; }
member this.DecodePixelWidth : int with get, set
Public Property DecodePixelWidth As Integer

属性值

Int32

图像解码后的宽度(以像素为单位)。 默认值为 0。

示例

下面的代码示例演示如何使用代码设置 DecodePixelWidth 属性。

// Define a BitmapImage.
Image myImage = new Image();
BitmapImage bi = new BitmapImage();

// Begin initialization.
bi.BeginInit();

// Set properties.
bi.CacheOption = BitmapCacheOption.OnDemand;
bi.CreateOptions = BitmapCreateOptions.DelayCreation;
bi.DecodePixelHeight = 125;
bi.DecodePixelWidth = 125;
bi.Rotation = Rotation.Rotate90;
MessageBox.Show(bi.IsDownloading.ToString());
bi.UriSource = new Uri("smiley.png", UriKind.Relative);

// End initialization.
bi.EndInit();
myImage.Source = bi;
myImage.Stretch = Stretch.None;
myImage.Margin = new Thickness(5);
' Define a BitmapImage.
Dim myImage As New Image()
Dim bi As New BitmapImage()

' Begin initialization.
bi.BeginInit()

' Set properties.
bi.CacheOption = BitmapCacheOption.OnDemand
bi.CreateOptions = BitmapCreateOptions.DelayCreation
bi.DecodePixelHeight = 125
bi.DecodePixelWidth = 125
bi.Rotation = Rotation.Rotate90
MessageBox.Show(bi.IsDownloading.ToString())
bi.UriSource = New Uri("smiley.png", UriKind.Relative)

' End initialization.
bi.EndInit()
myImage.Source = bi
myImage.Stretch = Stretch.None
myImage.Margin = New Thickness(5)

注解

如果 DecodePixelHeight 还设置,则忽略位图的纵横比。 如果未 DecodePixelHeight 设置,纵横比保持不变。

JPEG 和可移植网络图形 (PNG) 编解码器本机将图像解码为指定大小;其他编解码器按原始大小解码图像,并将图像缩放为所需大小。

依赖项属性信息

标识符字段 DecodePixelWidthProperty
元数据属性设置为 true

适用于

另请参阅