0

缩放图像视图时,我允许图像在捏缩放时变得小于最小尺寸,然后在onScaleEnd方法中恢复到最小尺寸。但是我遇到了一个问题:

transformMatrix = new Matrix()语句和构造函数之间没有区别transformMatrix = child.getImageMatrix()- 我已经检查过,两个赋值都将返回矩阵: [1, 0, 0][0, 1, 0][0, 0, 1]... 但是对于出于某种原因,它们的工作方式不同

这是图像缩放的地方:

public boolean onScale(ScaleGestureDetector detector) {
        //update the current scale
        float oldScaleFactor = scaleFactor;
        scaleFactor *= detector.getScaleFactor();


        if(Math.abs(oldScaleFactor - scaleFactor) < 0.02 * scaleFactor){
            // don't update scale Factor if the event isn't being handled
            scaleFactor = oldScaleFactor; 
            return false; 
            // should prevent against changes from resting fingers in place
        }
        else{    
             float xDiff = initialFocalPoints[0] - currentFocalPoints[0];
             float yDiff = initialFocalPoints[1] - currentFocalPoints[1];

            transformMatrix.setScale(scaleFactor, scaleFactor,
                               currentFocalPoints[0], currentFocalPoints[1]);
            transformMatrix.postTranslate(xDiff, yDiff);

            child.setImageMatrix(transformMatrix);
            return true;
        }
    }

这是我调整到正确最小值的地方:

@Override
public void onScaleEnd(ScaleGestureDetector detector){
        //making sure the zoom level is within the allowable bounds
        if(scaleFactor < ZOOM_LEVEL_5 || scaleFactor > 8.0f){
        scaleFactor = Math.max(ZOOM_LEVEL_5, Math.min(scaleFactor, 8.0f));
        float xDiff = initialFocalPoints[0] - currentFocalPoints[0];
        float yDiff = initialFocalPoints[1] - currentFocalPoints[1];

        transformMatrix.setScale(scaleFactor, scaleFactor,
                           currentFocalPoints[0], currentFocalPoints[1]);
        transformMatrix.postTranslate(xDiff, yDiff);


        child.setImageMatrix(transformMatrix);
    }
}

当我transformMatrix = new Matrix()在构造函数中设置时,一切正常,但这不起作用transformMatrix = child.getImageMatrix()- 图像不会弹回正确的最小尺寸......这是怎么回事?

帮助!

编辑:这是构造函数和onScaleBegin

public ScaleListener(){
        super();
        transformMatrix = new Matrix();
        transformMatrix = child.getImageMatrix();
        inverseTransformMatrix = new Matrix();
        currentFocalPoints = new float[2];
}

@Override
    public boolean onScaleBegin(ScaleGestureDetector detector){

        float startX = detector.getFocusX() + getScrollX();
        float startY = detector.getFocusY() + getScrollY();

        initialFocalPoints = new float[]{startX, startY};

        if(transformMatrix.invert(inverseTransformMatrix))
            inverseTransformMatrix.mapPoints(currentFocalPoints, initialFocalPoints);

        return true;
    }
4

1 回答 1

0

我还没有确定为什么会这样,但我可以通过调用来解决这个问题transformMatrix = new Matrix(child.getImageMatrix())。这样,它包含子 imageView 矩阵的副本并且可以修改。

于 2013-10-04T14:39:49.743 回答