Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to zoom in and zoom out Images in WP7?

I have made an application which displays Images .Now I want to implement zoom in and zoom out feature(by using two fingertip's) as in native windows phone photo viewer application.Any idea on how to proceed .

Thanks in Advance.

like image 863
Vaysage Avatar asked Jan 13 '11 09:01

Vaysage


2 Answers

Perhaps the most expedient approach would be to include the Silverlight for Windows Phone Toolkit. This contains a GestureService that will help with pinch and rotate touch gestures. You could apply it to an image like this:-

 <Image Source="someSourceUrl" RenderTransformOrigin="0.5, 0.5" CacheMode="BitmapCache">
     <Image.RenderTransform>
         <CompositeTransform x:Name="transform" />
     </Image.RenderTransform>
     <toolkit:GestureService.GestureListener>
         <toolkit:GestureListener PinchStarted="OnPinchStarted" PinchDelta="OnPinchDelta" />
     </toolkit:GestureService.GestureListener>
 </Image>

Then in code-behind:-

    private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
    {
        initialAngle = transform.Rotation;
        initialScale = transform.ScaleX;
    }

    private void OnPinchDelta(object sender, PinchGestureEventArgs e)
    {
        transform.Rotation = initialAngle + e.TotalAngleDelta;
        transform.ScaleX = initialScale * e.DistanceRatio;
        transform.ScaleY = initialScale * e.DistanceRatio;
    }
like image 119
AnthonyWJones Avatar answered Nov 17 '22 10:11

AnthonyWJones


Check out Laurent Bugnion's multitouch sample - http://multitouch.codeplex.com/

like image 21
AarthiR Avatar answered Nov 17 '22 12:11

AarthiR