title: How to determine scale factor in android
body: <p>How to determine scale factor after zoom. I am using below code for pinch zoom. After zoom I have to draw circle on bitmap at correct location. I heard this the formula we have to use to draw at correct point after zoom. </p>
  
  <p>Formula:  </p>
  
  <pre><code> float x = ev.getX() / mScaleFactor + rect.left;  
   float y = ev.getY() / mScaleFactor + rect.top;
  </code></pre>
  
  <p>I have no idea how to calculate mScaleFactor.</p>
  
  <p>I am using below code for pinch zoom,</p>
  
  <pre><code>  public boolean onTouch(View v, MotionEvent rawEvent) {
    WrapMotionEvent event = WrapMotionEvent.wrap(rawEvent);
    // ...
    ImageView view = (ImageView) v;
  
    // Dump touch event to log
    dumpEvent(event);
  
    // Handle touch events here...
    switch (event.getAction() &amp; MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
       savedMatrix.set(matrix);
       start.set(event.getX(), event.getY());
       Log.d(TAG, "mode=DRAG");
       mode = DRAG;
       break;
    case MotionEvent.ACTION_POINTER_DOWN:
       oldDist = spacing(event);
       Log.d(TAG, "oldDist=" + oldDist);
       if (oldDist &gt; 10f) {
          savedMatrix.set(matrix);
          midPoint(mid, event);
          mode = ZOOM;
          Log.d(TAG, "mode=ZOOM");
       }
       break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
       mode = NONE;
       Log.d(TAG, "mode=NONE");
       break;
    case MotionEvent.ACTION_MOVE:
       if (mode == DRAG) {
          // ...
          matrix.set(savedMatrix);
          matrix.postTranslate(event.getX() - start.x,
                event.getY() - start.y);
       }
       else if (mode == ZOOM) {
          float newDist = spacing(event);
          Log.d(TAG, "newDist=" + newDist);
          if (newDist &gt; 10f) {
             matrix.set(savedMatrix);
             float scale = newDist / oldDist;
             matrix.postScale(scale, scale, mid.x, mid.y);
          }
       }
       break;
    }
  
    view.setImageMatrix(matrix);
    return true; // indicate event was handled
  </code></pre>
  
  <p>}</p>
  
  <p>I am using imageview for displaying the image and zoom.
  Using canvas and bitmap I am drawing the circle and setting to the image view after draw.</p>
  
  <p>How to calculate scale factor for above pinch zoom code ?</p>
  
  <p>Thanks in advance.</p>