title: android zoom image using matrix
body: <p>I've the following code for implementing zoom image in Android:</p>
  
  <pre><code>public class MyActivity extends Activity{
  Matrix matrix = new Matrix();
      Matrix savedMatrix = new Matrix();
      float scaleWidth, scaleHeight,screenWidth,screenHeight;
      ImageView imageView;
  @Override
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          Display display = ((WindowManager) getApplicationContext()
                  .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
          screenWidth=display.getWidth();
          screenHeight=display.getHeight();
          imageView = (ImageView) findViewById(R.id.imageview);
          imageView.setScaleType(ScaleType.MATRIX);
          Bitmap cur_bm = BitmapFactory.decodeResource(getResources(),
                  R.drawable.myimage);
          float imageWidth = (float) cur_bm.getWidth();
          float imageHeight = (float) cur_bm.getHeight();
          float newHeight = screenHeight;
          float newWidth = screenWidth;
          scaleWidth = screenWidth / imageWidth;
          scaleHeight = newHeight / imageHeight;
          imageView.setImageBitmap(cur_bm);
          SetImageMatrix();
      }
  
      void SetImageMatrix() {
          Matrix mtrx = new Matrix();
          scaleWidth+=0.6;
          scaleHeight+=0.6;
          mtrx.postScale(scaleWidth, scaleHeight,screenWidth/2, screenHeight/2);
          imageView.setImageMatrix(mtrx);
          imageView.invalidate();
      }
  }
  </code></pre>
  
  <p>If I comment the line <code>imageView.setScaleType(ScaleType.MATRIX);</code> and comment out the function SetImageMatrix(), then the image appears as follows in the emulator:
  <img src="https://i.stack.imgur.com/ZAraf.jpg" alt="enter image description here"></p>
  
  <p>But if I uncomment the line <code>imageView.setScaleType(ScaleType.MATRIX);</code> and keep the function commented, then the image appears as follows in the emulator:</p>
  
  <p><img src="https://i.stack.imgur.com/K76gs.jpg" alt="enter image description here"></p>
  
  <p>Just setting the scaleType to MATRIX causes the image to scale down. Could someone please tell why this happens and how to overcome this issue?</p>