在Windows Surface 2.0中操作图像(旋转)

时间:2013-07-24 06:55:21

标签: c# wpf pixelsense

我正在使用c#wpf for windows surface 2.0。

我一直在使用我在xmpl文件中导入的一组图像。

我找到了一些文本示例,但是对于图像,他们使用GDI +来处理图像并为它们制作动画,但我不希望这样。

我现在要做的主要是旋转(变换旋转)图像并显示它正在旋转。

以下是我处理图片的方式:

Canvas.SetTop(image1, 0);
Canvas.SetLeft(image1, 200);

非常感谢任何帮助。

谢谢。

2 个答案:

答案 0 :(得分:3)

如果您想自动旋转图像而无需用户互动,请检查Clemens的答案。但是,如果你想通过触摸操作进行旋转,我发现很容易将图像放在ScatterViewItem中,如下所示:

<s:ScatterView>
    <s:ScatterViewItem CanMove="False" CanScale="False">
        <s:ScatterViewItem.Background>
            <ImageBrush ImageSource="yourImage.png" Stretch="UniformToFill"/>
        </s:ScatterViewItem.Background>
    </s:ScatterViewItem>
</s:ScatterView>

当然,您需要投入ScatterView及其内容

答案 1 :(得分:2)

您的问题并不是非常具体,有很多方法可以为图像的旋转设置动画。

一种简单的方法是将RotateTransform分配给图像控件的RenderTransform,然后为这些RotateTransforms的Angle属性设置动画。

<Image x:Name="image" Source="..."
       RenderTransformOrigin="0.5,0.5">
    <Image.RenderTransform>
        <RotateTransform/>
    </Image.RenderTransform>
</Image>

使用以下代码启动动画:

var transform = (RotateTransform)image.RenderTransform;
var animation = new DoubleAnimation(360, TimeSpan.FromSeconds(5));
transform.BeginAnimation(RotateTransform.AngleProperty, animation);

您可以在MSDN上的Animation Overview文章中开始阅读WPF中的动画。 Transforms Overview文章也可能有所帮助。

相关问题