【问题标题】:How can I rotate an image and make it fill the available space in Windows Phone 7?如何旋转图像并使其填充 Windows Phone 7 中的可用空间?
【发布时间】:2012-02-17 01:37:00
【问题描述】:

好的,我有这张 1000x500 的图片。所以我在 WP7 中这样显示它:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0" Background="{StaticResource PhoneAccentBrush}">
    <Image Name="image1" />
</Grid>

在我在代码中设置图像的内容后,它呈现如下:

还不错,但是我的业务需求是垂直显示,所以需要旋转一下。很简单:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0" Background="{StaticResource PhoneAccentBrush}">
    <Image Name="image1" RenderTransformOrigin="0.5 0.5">
        <Image.RenderTransform>
            <RotateTransform Angle="90"></RotateTransform>
        </Image.RenderTransform>
    </Image>
</Grid>

结果是:

好的,这就是想法,但我希望图像尽可能地拉伸。图像比屏幕的尺寸大,所以应该很容易。

相反,看起来正在发生的事情是图像呈现水平填充屏幕时的尺寸,然后 那个 是旋转的。

好的,所以他们有这个“拉伸”参数。让我们看看它有什么作用。

好吧,将其设置为“统一”没有任何作用

将其设置为“填充”:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0" Background="{StaticResource PhoneAccentBrush}">
    <Image Name="image1" RenderTransformOrigin="0.5 0.5" Stretch="Fill">
        <Image.RenderTransform>
            <RotateTransform Angle="90"></RotateTransform>
        </Image.RenderTransform>
    </Image>
</Grid>

看起来它只是水平拉伸旋转的图像,这不是我想要的。

而“UniformToFill”就是这样做的:

我什至不知道那里发生了什么。

我必须说,在为 iOS 和 Android 编写了这个应用程序之后,由于我十年来的专长一直在 C# 中,现在我在云雀上开发了 WP7 版本,微软真的用 WP7 搞定了很多东西。它使用起来很简单,很明显他们已经在其中投入了大量工作,并成功地利用了他们现有的技术(.NET CE、Silverlight 等)

所以令人费解的是为什么在浏览了这个应用程序中的所有其他内容之后,我无法获得一个简单的图像来旋转和缩放。

有人知道我在这里遗漏了什么或做错了什么吗?我所需要的只是旋转 90 度然后填满屏幕,所以我为 WP7 看到的更精细的旋转解决方案在这里并不适用。

【问题讨论】:

    标签: c# silverlight image windows-phone-7 rotation


    【解决方案1】:

    RenderTransform 的问题在于它不会将大小/方向的变化传播到父控件。在 WPF 中有 LayoutTransform 可以完成此操作。

    Luckily you are not alone and the Silverlight toolkit provides a solution 调用:LayoutTransformer

    For the windows Phone you can find a port by David Anson here

    【讨论】:

    • 那么,我下载/安装了 Silverlight 工具包,它适用于 Windows Phone 7 的东西吗?
    • 一旦我将引用添加到正确的位置,它就可以完美运行。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-11
    • 2016-10-17
    • 2018-08-18
    • 1970-01-01
    • 2022-01-16
    相关资源
    最近更新 更多