TransformedBitmap.Transform Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets the Transform, which specifies the scale or rotation of the bitmap.

Namespace:   System.Windows.Media.Imaging
Assembly:  PresentationCore (in PresentationCore.dll)

public Transform Transform { get; set; }

Property Value

Type: System.Windows.Media.Transform

The Transform, which specifies the scale or rotation of the bitmap. The default value is Identity.

TransformedBitmap supports only orthogonal transforms such as rotation transforms of 90 increments and scale transforms. Transforms that skew the image are not supported.

Identifier field

TransformProperty

Metadata properties set to true

None

The following example shows how to apply a Transform to a bitmap.

<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;

.NET Framework
Available since 3.0
Return to top
Show: