图像缩放不正确

时间:2012-01-09 06:49:25

标签: android image zoom

我想捏缩放图像,但问题是当我缩放它不会放大和缩小我的手指所在的位置。它转到0,0点。

这是我的代码:

@Override
public boolean onScale(ScaleGestureDetector detector) {
    mScaleFactor = detector.getScaleFactor();

    Log.e("ScaleFactor", "" + mScaleFactor);

    // Don't let the object get too small or too large.
    mScaleFactor = Math.max(0.4f, Math.min(mScaleFactor, 5.0f));
    if(mScaleFactor>=1)
        mScaleFactor=1f;

    invalidate();
    return true;
}

我尝试了很多,但可以通过任何方式解决这个问题。

1 个答案:

答案 0 :(得分:0)

很有用

private float[] matrixValues = new float[9];
private float maxZoom;
private float minZoom;
private float height;
private float width;
private RectF viewRect; 


private void init() {
    maxZoom = 4;
    minZoom = 0.25f;
    height = myimage.getDrawable().getIntrinsicHeight()+20;
    width = myimage.getDrawable().getIntrinsicWidth()+20;
    viewRect = new RectF(0, 0, myimage.getWidth()+20, myimage.getHeight()+20);
}