0

我有一个稍微修改的要求。这篇文章保留了方向变化的缩放并使其居中。我不希望图像居中对齐。我只想保持缩放。如何做到这一点?任何帮助将不胜感激。

4

1 回答 1

1

经过这么多头脑风暴后,我实现了预期的行为。想法是保存之前的矩阵和图像的缩放比例,然后在图像上填充之前存储的矩阵。获取以前的值:

Matrix previousImageMatrix = photoView.getDisplayMatrix();
previousImageMatrix.getValues(previousValues);
previousZoomLevel = prescription.getScale();

现在附加photoView.getViewTreeObserver().addOnPreDrawListener(this);在图像缩放时填充上述矩阵的onPreDraw()方法如下:

@Override
public boolean onPreDraw()
{
    photoView.getViewTreeObserver().removeOnPreDrawListener(this);
    Matrix theMatrix = photoView.getDisplayMatrix();
    Log.d("***", "onPreDraw: TransX = " + previousValues[2] + "TransY = " + previousValues[5]);
    float[] matrixValues = new float[9];
    matrixValues[0] = previousZoomLevel; // 0 and 4 store the scaleX and scaleY
    matrixValues[4] = previousZoomLevel;
    if (previousZoomLevel == MIN_ZOOM_LEVEL) // Zoom Level starts from 1.0 to 16.0
    {
        matrixValues[2] = 0; //2 and 5 store store TransX and TransY
        matrixValues[5] = 0;
    } else
    {
        matrixValues[2] = previousValues[2];
        matrixValues[5] = previousValues[5];
    }

    Log.d("***", "onPreDraw: NEW.. TransX = " + matrixValues[2] + "TransY = " + matrixValues[5]);
    matrixValues[8] = 1.0f;
    theMatrix.setValues(matrixValues);
    prescription.setDisplayMatrix(theMatrix);

    Matrix theImageViewMatrix = photoView.getDisplayMatrix();
    prescription.setImageMatrix(theImageViewMatrix);
    return true;
}

希望这可以帮助某人。

于 2016-12-21T13:32:41.307 回答