Rotate image using RotateTransform issue with offsets

Here is my XAML:

<Image VerticalAlignment="Center" HorizontalAlignment="Center" Source="{Binding Input, Converter={StaticResource ByteArrayToBitmapConverter}}"> <Image.RenderTransform> <RotateTransform Angle="{Binding RotateAngle}" CenterX="100" CenterY="100"></RotateTransform> </Image.RenderTransform> </Image> 

I bind the image to the data source and use the converter to get the Bitmap. This part works. However, I want it to spin, and I install RotateAngle in my virtual machine. The problem is that all images have different sizes, I don’t know how to install CenterX and CenterY. Is there any other way to just change the orientation without calculating extra X and Y?

+4
source share
1 answer

I don’t have time to test this myself, but I think that RenderTransformOrigin might work for you.

 <Image VerticalAlignment="Center" HorizontalAlignment="Center" 
Source="{Binding Input, Converter={StaticResource ByteArrayToBitmapConverter}}" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform> <RotateTransform Angle="{Binding RotateAngle}" > </RotateTransform> </Image.RenderTransform> </Image> </code></pre>
+6
source

Source: https://habr.com/ru/post/1393424/


All Articles