Windows Phone Image Pinch & Zoom Reset -


i using code pinch , zoom , working correctly have reset on double tap.

my xaml code;

 <grid x:name="contentpanel" grid.row="1" margin="12,0,12,0">         <viewportcontrol x:name="viewport"               manipulationstarted="onmanipulationstarted" manipulationdelta="onmanipulationdelta"                            manipulationcompleted="onmanipulationcompleted" viewportchanged="viewport_viewportchanged">             <canvas x:name="canvas">                 <image x:name="testimage" source="/assets/test.jpg"                           rendertransformorigin="0,0" cachemode="bitmapcache"                        imageopened="onimageopened">                     <image.rendertransform>                         <scaletransform x:name="xform"/>                     </image.rendertransform>                 </image>             </canvas>         </viewportcontrol>     </grid> 

my variables:

const double maxscale = 10;      double _scale = 1.0;     double _minscale;     double _coercedscale;     double _originalscale;      size _viewportsize;     bool _pinching;     point _screenmidpoint;     point _relativemidpoint;      bitmapimage _bitmap; 

and methods ;

    void viewport_viewportchanged(object sender, system.windows.controls.primitives.viewportchangedeventargs e)     {         size newsize = new size(viewport.viewport.width, viewport.viewport.height);         if (newsize != _viewportsize)         {             _viewportsize = newsize;             coercescale(true);             resizeimage(false);         }     }       void onmanipulationstarted(object sender, manipulationstartedeventargs e)     {         _pinching = false;         _originalscale = _scale;     }       void onmanipulationdelta(object sender, manipulationdeltaeventargs e)     {         if (e.pinchmanipulation != null)         {             e.handled = true;              if (!_pinching)             {                 _pinching = true;                 point center = e.pinchmanipulation.original.center;                 _relativemidpoint = new point(center.x / testimage.actualwidth, center.y / testimage.actualheight);                  var xform = testimage.transformtovisual(viewport);                 _screenmidpoint = xform.transform(center);             }              _scale = _originalscale * e.pinchmanipulation.cumulativescale;              coercescale(false);             resizeimage(false);         }         else if (_pinching)         {             _pinching = false;             _originalscale = _scale = _coercedscale;         }     }       void onmanipulationcompleted(object sender, manipulationcompletedeventargs e)     {         _pinching = false;         _scale = _coercedscale;     }        void onimageopened(object sender, routedeventargs e)     {         _bitmap = (bitmapimage)testimage.source;         _scale = 0;         coercescale(true);         _scale = _coercedscale;          resizeimage(true);     }       void resizeimage(bool center)     {         if (_coercedscale != 0 && _bitmap != null)         {             double newwidth = canvas.width = math.round(_bitmap.pixelwidth * _coercedscale);             double newheight = canvas.height = math.round(_bitmap.pixelheight * _coercedscale);              xform.scalex = xform.scaley = _coercedscale;              viewport.bounds = new rect(0, 0, newwidth, newheight);              if (center)             {                 viewport.setviewportorigin(                     new point(                         math.round((newwidth - viewport.actualwidth) / 2),                         math.round((newheight - viewport.actualheight) / 2)                         ));             }             else             {                 point newimgmid = new point(newwidth * _relativemidpoint.x, newheight * _relativemidpoint.y);                 point origin = new point(newimgmid.x - _screenmidpoint.x, newimgmid.y - _screenmidpoint.y);                 viewport.setviewportorigin(origin);             }         }     }       void coercescale(bool recompute)     {         if (recompute && _bitmap != null && viewport != null)         {             double minx = viewport.actualwidth / _bitmap.pixelwidth;             double miny = viewport.actualheight / _bitmap.pixelheight;              _minscale = math.min(minx, miny);         }          _coercedscale = math.min(maxscale, math.max(_scale, _minscale));      }  private void imgzoom_doubletap(object sender, system.windows.input.gestureeventargs e)     {         //reset viewport , image     } 

how can reset viewport , image use them another?

thanks.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -