2

提前致谢..

在我的 WP7 应用程序中,我使用了以下代码来缩放图像。

<Image Name="imgThumbnail" Width="480" Height="740" VerticalAlignment="Center" HorizontalAlignment="Center" RenderTransformOrigin="0.5, 0.5" CacheMode="BitmapCache">
    <Image.RenderTransform>
        <CompositeTransform x:Name="transform" />
    </Image.RenderTransform>
    <toolkit:GestureService.GestureListener>
        <toolkit:GestureListener PinchDelta="OnPinchDelta" PinchStarted="OnPinchStarted" />
    </toolkit:GestureService.GestureListener>
</Image>

private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
{
    var image = sender as System.Windows.Controls.Image;
    if (image == null) return;
    var transform = image.RenderTransform as CompositeTransform;
    if (transform == null) return;
    initialScale = transform.ScaleX;
}
private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
    var image = sender as System.Windows.Controls.Image;
    if (image == null) return;
    var transform = image.RenderTransform as CompositeTransform;
    if (transform == null) return;
    transform.ScaleX = initialScale * e.DistanceRatio;
    transform.ScaleY = initialScale * e.DistanceRatio;
}

缩放工作正常,但我无法滚动图像。添加滚动查看器时,缩放不起作用。有什么问题,我该如何解决这个问题?

4

1 回答 1

3

尝试使用 Laurent Bugnion 的这个库对图像进行捏合和缩放:https ://multitouch.codeplex.com/ - 它处理“真正的”捏合和缩放行为所需的计算。

代码将类似于:

<Image CacheMode="BitmapCache" Name="imgThumbnail"  Margin="0,0,0,80" Source="test.jpg">
        <i:Interaction.Behaviors>
            <behaviors:MultiTouchBehavior IsDebugModeActive="False"
                                   AreFingersVisible="True"
                                   IsMockActive="True"                                       
                                   MaximumScale="3"
                                   MinimumScale="0.8"
                                   IsScaleEnabled="True"
                                   IsRotateEnabled="False"
                                   IsTranslateXEnabled="True"
                                   IsTranslateYEnabled="True"/>
        </i:Interaction.Behaviors>
    </Image>

如果您确实想尝试自己实现此功能,我建议您阅读 Francesco De Vittori 的这篇文章(http://www.frenk.com/2011/03/windows-phone-7-correct-pinch-zoom-in-银光/)。

于 2012-05-29T12:38:03.437 回答