title: How to zoom in and Zoom out bitmap in android canvas from multiple bitmap?
body: <p>I have created <code>bitmap</code> on android canvas and I want zoom-in and zoom-out I am storing images on <code>Arraylist</code> . It's zooming correctly but when there is multiple <code>bitmap</code> all the <code>bitmap</code> zoom-in and zoom-out. I want to Zoom only Specific <code>bitmap</code> which I touch. In My code there is Functionality to drag image it work completely but when <code>bitmap</code> zoomed its or working.</p>
  
  <p>Here is  code</p>
  
  <pre><code>public class ZoomView extends View {
  
  images touchedCircle;
  
  
  
  private ScaleGestureDetector scaleDetector;
  private float scaleFactor = 1.f;
  
  
  private BitmapDrawable bitmap;
  
  
  private HashSet&lt;images&gt; img = new HashSet&lt;images&gt;(CIRCLES_LIMIT);
  private SparseArray&lt;images&gt; mCirclePointer = new SparseArray&lt;images&gt;(CIRCLES_LIMIT)
  
  
  public ZoomView(Context context) {
      this(context, null);
  }
  
  public ZoomView(Context context, AttributeSet attrs) {
      super(context, attrs);
      mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mPaint.setStyle(Style.STROKE);
      mPaint.setColor(Color.BLACK);
      mPaint.setStrokeWidth(5);
      mPaint.setStrokeCap(Paint.Cap.ROUND);
  
      bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.deleteforever);
  
  
      bitmap = (BitmapDrawable) getResources().getDrawable(R.drawable.mesej);
      scaleDetector = new ScaleGestureDetector(context, new ScaleListener());
  
  }
  
   @Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
  
      for (images img1 : img) {
  
          canvas.save();
          canvas.scale(scaleFactor, scaleFactor);
          canvas.drawBitmap(bitmap.getBitmap(), img1.centerX, img1.centerY, null);
          canvas.restore();
      }
  }
  
      @Override
      public boolean onTouchEvent(final MotionEvent event) {
      boolean handled = false;
  
      scaleDetector.onTouchEvent(event);
      images touchedCircle;
  
      switch (event.getActionMasked()) {
          case MotionEvent.ACTION_DOWN:
  
            xTouch = event.getX(0);
            yTouch = event.getY(0);
  
            touchedCircle = obtainTouchedCircle(xTouch, yTouch);
            touchedCircle.centerX = xTouch;
            touchedCircle.centerY = yTouch;
            touchedtext = obtainTouchedText(xTouch2, yTouch2);
            mCirclePointer.put(event.getPointerId(0), touchedCircle);
  
  
  
              invalidate();
              handled = true;
              break;
  
          case MotionEvent.ACTION_MOVE:
  
          touchedCircle = mCirclePointer.get(pointerId);
  
                  if (!scaleDetector.isInProgress()){
                      if (null != touchedCircle) {
  
                          touchedCircle.centerX = xTouch - bitmap.getBitmap().getWidth() / 2;
                          touchedCircle.centerY = yTouch - bitmap.getBitmap().getHeight() / 2;
                          invalidate();
                      }
                  }
  
  
              invalidate();
              handled = true;
              break;
  
          case MotionEvent.ACTION_UP:
  
          invalidate();
           handled = true;
           break;
  
  
          case MotionEvent.ACTION_POINTER_UP:
  
              mCirclePointer.remove(pointerId);
              invalidate();
              handled = true;
              break; 
  
  
          case MotionEvent.ACTION_CANCEL:
              zooming=false;
              invalidate();
              handled = true;
              break;
  
          default:
              break;
      }
      invalidate();
      return super.onTouchEvent(event) || handled;
  
      }
  
       private static class images {
      int radius;
      float centerX;
      float centerY;
  
      images(float X, float Y) {
          this.centerX = X;
          this.centerY = Y;
          this.radius = radius;
      }
  
  
  
  private images obtainTouchedCircle(final float xTouch, final float yTouch) {
      images touchedCircle = getTouchedCircle(xTouch, yTouch);
  
      if (null == touchedCircle) {
          touchedCircle = new images(xTouch, yTouch);
  
          if (img.size() == CIRCLES_LIMIT) {
              img.clear();
          }
  
          if (c.getImage() == 1) {
              img.add(touchedCircle);
          }
      }
  
      return touchedCircle;
  }
  
  
  private images getTouchedCircle(final float xTouch, final float yTouch) {
      images touched = null;
  
      for (images circle : img) {
  
          if ((circle.centerX &lt; xTouch) &amp;&amp; (circle.centerY &lt; yTouch)) {
  
              float bitmap_width =bitmap.getBitmap().getWidth();
              float bitmap_height = bitmap.getBitmap().getHeight();
  
              float width = circle.centerX + bitmap_width;
              float height = circle.centerY + bitmap_height;
  
  
              if ((xTouch &lt; circle.centerX + bitmap.getBitmap().getWidth()) &amp;&amp; (yTouch &lt; circle.centerY + bitmap.getBitmap().getHeight())) {
  
                  touched = circle;
                  break;
              }
          }
      }
      return touched;
  }
  
  
  private class ScaleListener extends
          ScaleGestureDetector.SimpleOnScaleGestureListener {
      @Override
      public boolean onScale(ScaleGestureDetector detector) {
          scaleFactor *= detector.getScaleFactor();
          scaleFactor = Math.max(0.1f, Math.min(scaleFactor, 3.0f));
          invalidate();
          return true;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks for Help in Advance...</p>