24 Mar 2012, 14:26
Generic-user-small

Neeraj Narang (1 post)

I tried implementing the code for zoom image using a matrix in android. But am getting the below issue. Could someone please help me out with this?

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);
    imageView.setImageBitmap(cur_bm);
} }

If I comment the line imageView.setScaleType(ScaleType.MATRIX); then the image is skewed. It doesn’t fill the screen.

But if I uncomment the line imageView.setScaleType(ScaleType.MATRIX); then the image fills the screen.

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?

12 Apr 2012, 17:56
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

Neeraj and I exchanged some email and he says this code does what he wants now:

Matrix m = imageView.getImageMatrix();

//Get the image’s rect RectF drawableRect = new RectF(0, 0, DrawView.imageWidth.floatValue(), DrawView.imageHeight.floatValue());

//Get the image view’s rect RectF viewRect = new RectF(0, 0, imageView.getWidth(), imageView.getHeight()); m.setRectToRect(drawableRect, viewRect, Matrix.ScaleToFit.CENTER);

//set scale m.postScale(scaleWidth.floatValue(), scaleHeight.floatValue(), x, y); imageView.setImageMatrix(m);

  You must be logged in to comment