在 Windows Phone 7 上使用 ScaleTransform 与 LayoutTransformer 和 Scrollviewer 时,部分图像丢失

发布于 2024-10-10 00:16:00 字数 1390 浏览 0 评论 0原文

我试图在 Windows Phone 7 应用程序的 ScrollViewer 中显示缩放图像。在应用程序页面上,我定义了如下控件:

        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Name="ImageScroller" HorizontalAlignment="Center" VerticalAlignment="Center">
            <layout:LayoutTransformer x:Name="LayoutTransformer">
                <layout:LayoutTransformer.LayoutTransform>
                    <ScaleTransform x:Name="ImageScale"/>
                </layout:LayoutTransformer.LayoutTransform>                    
                <Image x:Name="Image" Margin="4" Source="{Binding ImageSource}"  />
            </layout:LayoutTransformer>
        </ScrollViewer>

LayoutTransformer 类来自 Silverlight 扩展项目。

我有处理 ZoomIn 和 ZoomOut 事件的方法,并且在那里执行以下操作:

    private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
    {
        // Zoom In 
        ImageScale.ScaleX = ImageScale.ScaleY = ImageScale.ScaleX + 0.5;
        LayoutTransformer.ApplyLayoutTransform();
        ImageScroller.InvalidateMeasure();
    }

但是,当我进行放大并且更改图像时,ScrollView 控件在图像的底部和右侧有空白区域。几乎就像图像被缩放但在缩放变换之前使用原始图像的大小进行裁剪一样。

有什么想法我做错了吗?

我还创建了一个重现此问题的项目: http://dl.dropbox.com /u/2598447/ZoomTest.WP7.zip

I am trying to have a scaled image in a ScrollViewer in my Windows Phone 7 application. On the application page I define the controls like this:

        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Name="ImageScroller" HorizontalAlignment="Center" VerticalAlignment="Center">
            <layout:LayoutTransformer x:Name="LayoutTransformer">
                <layout:LayoutTransformer.LayoutTransform>
                    <ScaleTransform x:Name="ImageScale"/>
                </layout:LayoutTransformer.LayoutTransform>                    
                <Image x:Name="Image" Margin="4" Source="{Binding ImageSource}"  />
            </layout:LayoutTransformer>
        </ScrollViewer>

The LayoutTransformer class is coming from the Silverlight Extension project.

I have methods to handle the ZoomIn and ZoomOut events and I do the following there:

    private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
    {
        // Zoom In 
        ImageScale.ScaleX = ImageScale.ScaleY = ImageScale.ScaleX + 0.5;
        LayoutTransformer.ApplyLayoutTransform();
        ImageScroller.InvalidateMeasure();
    }

However when I have a Zoom-In and the Image is changed the ScrollView control has empty area at the bottom and at the right side of the Image. Almost as if the Image was scaled but clipped using the size of the original image before the scale transform.

Any ideas what I am doing wrong?

I also created a project that reproduces this problem: http://dl.dropbox.com/u/2598447/ZoomTest.WP7.zip

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2024-10-17 00:16:00

我终于收到了微软的 David Anson 的一些答复,并希望能找到解决方案。这是他的评论,但您也可以在他的博客上阅读他的回答:

您的手机可以变成机器人 - LayoutTransformer 在 Windows Phone 平台上运行良好

感谢您的精彩演示!
这个问题原来是由于
Windows 上 Silverlight 的限制
Phone 7 - UI 元素大于
2048x2048 被剪裁到该尺寸
显示时。这是一个链接
有关的更多信息
问题:

stackoverflow.com/.../bitmapimage-size-restrictions-in-silverlight

在您的示例中,测试图像是
1201x1401,我首先注意到剪裁
3 次“放大”后 - 对应
变焦倍数为 1.9 倍 - 其中
转换为有效图像尺寸
2282x2662 - 超过
两个方向的限制。正在做的
数学来计算这个金额
超过 2048 给出 234
水平方向和 614
垂直的。现在将这些数字保留在
记住并一直滚动到
ScrollViewer 的右下角
您手机的 480x800 屏幕。注意
水平黑色空间的量
大约是屏幕宽度的一半
(即~240px)和垂直黑色
空间约为四分之三
屏幕高度(即 600px) - 因为
这些估计非常吻合
加上我们刚刚计算的超额部分,
我相当有信心你正在跑步
进入这个问题。

不幸的是,这是一个平台
限制(你已经
通过运行您的场景来确认
在桌面 Silverlight 上成功)
因此我无法做到
直接在LayoutTransformer中修复。
幸运的是,有一些
中讨论的解决方法
上面的线程/链接。

抱歉给您带来麻烦 - 我希望如此
有帮助!

另外,答案中还引用了一篇 stackoverflow 文章,描述了此问题的根本原因是 Windows Phone 7 平台限制:

Silverlight 中的位图图像大小限制

I finally received some answer and hopefully a solution from David Anson of Microsoft. Here is his comment, but you can also read his answer on his blog:

Your phone can turn into a robot - LayoutTransformer works great on the Windows Phone platform

Thanks for the great demonstration!
This problem turns out to be due to a
limitation of Silverlight on Windows
Phone 7 - that UI elements larger than
2048x2048 get clipped to that size
when being displayed. Here's a link to
some more information about the
problem:

stackoverflow.com/.../bitmapimage-size-restrictions-in-silverlight

In your example, the test image is
1201x1401 and I first notice clipping
after 3 "Zoom In"s - which corresponds
to a zoom factor of 1.9x - which
translates to an effective image size
of 2282x2662 - which exceeds the
limits in both directions. Doing the
math to compute the amount this
exceeds 2048 gives 234 in the
horizontal direction and 614 in the
vertical. Now keep those numbers in
mind and scroll all the way to the
bottom-right of the ScrollViewer on
your phone's 480x800 screen. Note that
the amount of horizontal black space
is approximately half the screen width
(i.e., ~240px) and the vertical black
space is about three quarters of the
screen height (i.e., 600px) - because
these estimates match up so closely
with the overages we've just computed,
I'm fairly confident you're running
into this problem.

Unfortunately, it's a platform
limitation (which you already
confirmed by running your scenario
successfully on desktop Silverlight)
and therefore not something I can
directly fix in LayoutTransformer.
Fortunately, there are some
workarounds which are discussed in the
thread/link above.

Sorry for the trouble - I hope this
helps!

Also there is a stackoverflow article is referenced in the answer describing the root cause of this problem as a Windows Phone 7 platform limitation:

BitmapImage size restrictions in Silverlight

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文