BitmapImage.Rotation 屬性

定義

取得或設定這個 BitmapImage 會旋轉的角度。Gets or sets the angle that this BitmapImage is rotated to.

public:
 property System::Windows::Media::Imaging::Rotation Rotation { System::Windows::Media::Imaging::Rotation get(); void set(System::Windows::Media::Imaging::Rotation value); };
public System.Windows.Media.Imaging.Rotation Rotation { get; set; }
member this.Rotation : System.Windows.Media.Imaging.Rotation with get, set
Public Property Rotation As Rotation

屬性值

用於 BitmapImage 的旋轉。The rotation that is used for the BitmapImage. 預設為 Rotate0The default is Rotate0.

範例

下列程式碼範例示範如何使用Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML)和程式碼來旋轉影像。The following code example demonstrates how to rotate an image by using Extensible Application Markup Language (XAML)Extensible Application Markup Language (XAML) and code.

<Image Width="150" Margin="5" Grid.Column="0" Grid.Row="1">
  <Image.Source>
    <TransformedBitmap Source="/sampleImages/watermelon.jpg" >
      <TransformedBitmap.Transform>
        <RotateTransform Angle="90"/>
      </TransformedBitmap.Transform>
    </TransformedBitmap>
  </Image.Source>
</Image>
// Create Image element.
Image rotated90 = new Image();
rotated90.Width = 150;

// Create the TransformedBitmap to use as the Image source.
TransformedBitmap tb = new TransformedBitmap();

// Create the source to use as the tb source.
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"sampleImages/watermelon.jpg", UriKind.RelativeOrAbsolute);
bi.EndInit();

// Properties must be set between BeginInit and EndInit calls.
tb.BeginInit();
tb.Source = bi;
// Set image rotation.
RotateTransform transform = new RotateTransform(90);
tb.Transform = transform;
tb.EndInit();
// Set the Image source.
rotated90.Source = tb;
' Create Image element.
Dim rotated90 As New Image()
rotated90.Width = 150

' Create the TransformedBitmap to use as the Image source.
Dim tb As New TransformedBitmap()

' Create the source to use as the tb source.
Dim bi As New BitmapImage()
bi.BeginInit()
bi.UriSource = New Uri("sampleImages/watermelon.jpg", UriKind.RelativeOrAbsolute)
bi.EndInit()

' Properties must be set between BeginInit and EndInit calls.
tb.BeginInit()
tb.Source = bi
' Set image rotation.
Dim transform As New RotateTransform(90)
tb.Transform = transform
tb.EndInit()
' Set the Image source.
rotated90.Source = tb

備註

旋轉會在調整後執行。Rotation is performed after scaling. 這表示, Rotation具有的Rotate90DecodePixelWidth 10 和DecodePixelHeight 5 的影像會產生寬度為5且高度為10的影像。This means that an image that has a Rotation of Rotate90, a DecodePixelWidth of 10, and DecodePixelHeight of 5 will result in an image that has a width of 5 and a height of 10.

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field RotationProperty
中繼資料屬性設定為trueMetadata properties set to true None

適用於

另請參閱