Created
December 25, 2021 09:52
-
-
Save hyuni/b6c24312871aeeb9da7c7328a8ead3f0 to your computer and use it in GitHub Desktop.
matrix rotate wrong position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onDraw(canvas: Canvas?) { | |
contentBitmap.draw(canvas) | |
// get rotate from matrix | |
val matrixRotate = contentBitmapLayer.matrix.rotation | |
// get contentBitmapLayer bounds from matrix | |
val x1 = bitmapPoints[0] | |
val y1 = bitmapPoints[1] | |
val x2 = bitmapPoints[2] | |
val y2 = bitmapPoints[3] | |
val x3 = bitmapPoints[4] | |
val y3 = bitmapPoints[5] | |
val x4 = bitmapPoints[6] | |
val y4 = bitmapPoints[7] | |
// calculate mid point | |
val contentMidPoint = calculateMidPoint() | |
val tx = contentMidPoint.x - (rotateIcon.width / 2).toFloat() | |
val ty = contentMidPoint.y - (rotateIcon.height / 2.toFloat()) | |
// rotateIcon draw start point | |
val nx = (w - rotateIcon.width) / 2.0f | |
val ny = rotateIcon.height + marginHeight | |
// rotateIcon center translate contentBitmap center | |
rotateIcon.matrix.setTranslate(tx, ty) | |
rotateIcon.matrix.postRotate(matrixRotate, rotateIcon.width / 2.toFloat(), rotateIcon.height / 2.toFloat()) | |
rotateIcon.matrix.postTranslate(-tx, -ty) | |
rotateIcon.matrix.postTranslate(x1 + nx, y1 - ny) | |
rotateIcon.draw(canvas) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment