简体   繁体   English

围绕点旋转图像并翻译

[英]Rotate Image around point and translate

I can rotate an Image around it's upper left corner but I need to rotate it around the blue x ("0.5,1").我可以围绕它的左上角旋转图像,但我需要围绕蓝色 x(“0.5,1”)旋转它。 RenderTransformOrigin doesn't do it. RenderTransformOrigin 不这样做。 My image also need to be translated to the Black Ellipse.我的图像也需要转换为黑色椭圆。

 <Image x:Name="hut1" Visibility="Visible" Stretch="Fill" Canvas.Left="0"  Canvas.Top="0" Height="100" Width="100" RenderTransformOrigin="0,0">
     <Image.RenderTransform>
           <TransformGroup>
                <ScaleTransform ScaleX="1" ScaleY="1"  />
                <RotateTransform CenterX="0" CenterY="0"  Angle="-11" />
                <TranslateTransform X="30" Y="150" />
          </TransformGroup>
    </Image.RenderTransform>
    <Image.Source>
          <BitmapImage UriSource="\Hat.png"/>
    </Image.Source>
</Image>

在此处输入图片说明

Set the Canvas.Left and Top properties to the same values that are applied to the Ellipse.Canvas.LeftTop属性设置为应用于椭圆的相同值。 Then use RenderTransformOrigin and TranslateTransform to transform the Image into the correct relative position:然后使用RenderTransformOriginTranslateTransform将 Image 转换为正确的相对位置:

<Image x:Name="hut1" Stretch="Fill"
       Canvas.Left="30" Canvas.Top="150"
       Height="100" Width="100"
       RenderTransformOrigin="0.5,1"
       Source="\Hat.png">
    <Image.RenderTransform>
         <TransformGroup>
             <ScaleTransform ScaleX="1" ScaleY="1" />
             <RotateTransform Angle="-11" />
             <TranslateTransform X="-50" Y="-100" />
         </TransformGroup>
     </Image.RenderTransform>
</Image>

One may as well first translate and then rotate the Image, and thus avoid the need for setting RenderTransformOrigin :也可以先平移再旋转图像,这样就不需要设置RenderTransformOrigin

<Image x:Name="hut1" Stretch="Fill"
       Canvas.Left="30" Canvas.Top="150"
       Height="100" Width="100"
       Source="\Hat.png">
    <Image.RenderTransform>
         <TransformGroup>
             <ScaleTransform ScaleX="1" ScaleY="1" />
             <TranslateTransform X="-50" Y="-100" />
             <RotateTransform Angle="-11" />
         </TransformGroup>
     </Image.RenderTransform>
</Image>

Here's a quick snippet from an image where the rotation point is bottom middle这是旋转点位于底部中间的图像的快速片段

HorizontalAlignment="Left" Height="100" Margin="196,99,0,0" VerticalAlignment="Top" Width="100" RenderTransformOrigin="0.523,1.111"/>

(RenderTransformOrigin in this example) (本例中为 RenderTransformOrigin)

Hope this helps you out :))希望这可以帮助你 :))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM