我正在将下面的译文翻译成我的矩阵
fun updateMatrix() {
// init matrix to E - identity matrix
matrix.reset()
// calculate params
var rotationInDegree = layer.rotationInDegrees
var scaleX = layer.scale
val scaleY = layer.scale
if (layer.isFlipped) {
// flip (by X-coordinate) if needed
rotationInDegree *= -1.0f
scaleX *= -1.0f
}
// applying transformations : L = S * R * T
// scale
matrix.preScale(scaleX, scaleY, absoluteCenterX(), absoluteCenterY())
// rotate
matrix.preRotate(rotationInDegree, absoluteCenterX(), absoluteCenterY())
// translate
matrix.preTranslate(getTopLeftX(), getTopLeftY())
// applying holy scale - S`, the result will be : L = S * R * T * S`
matrix.preScale(holyScale, holyScale)
}
然后将该矩阵保存到我的数据库中。我想要的是获取我的位图的坐标而不会发生旋转。到目前为止,我所想的是下面的代码
float[] values = new float[9];
tempMatrix.getValues(values);
int rotation = (int) Math.round((-Math.atan2(values[Matrix.MSKEW_X], values[Matrix.MSCALE_X]) * (180 / Math.PI)));
if (rotation != 0) {
tempMatrix.preRotate(-rotation);
tempMatrix.getValues(values);
}
final float panX = values[Matrix.MTRANS_X];
final float panY = values[Matrix.MTRANS_Y];
但是panX
和panY
是不正确的,即使我不执行tempMatrix.preRotate(-rotation);
也总是一样。我还能做些什么来获取那些正确的坐标?