24 Mar 2012, 14:26

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;

public void onCreate(Bundle savedInstanceState) {
    Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    imageView = (ImageView) findViewById(R.id.imageview);
    Bitmap cur_bm = BitmapFactory.decodeResource(getResources(),
} }

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

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);

17 Apr 2014, 19:45

aeimage image (1 post)

[ this post might be spam… ]

it seems so, it is a good way to zoom images using a matrix in android. i also found some c# codes here to help you guys.

17 Apr 2014, 19:45

myfun fun (3 posts)

[ this post might be spam… ]

use image viewer to zoom in and zoom out image can be a good way as well. thanks for sharing the codes about to for image viewing.

  You must be logged in to comment