naver / android-imagecropview

android image crop library
Apache License 2.0
254 stars 55 forks source link

How to change rotation image view? #53

Open jackyhieu1211-hn opened 4 years ago

jackyhieu1211-hn commented 4 years ago

Hello admin How to change rotation image view? Thanks

jackyhieu1211-hn commented 4 years ago

Hello. Because the library does not support rotation. But if you want to rotate the image. You can do the following

I use kotlin

`

private var currentAngle = 0.0f
private fun rotateByAngle() {
    if (currentAngle == -270f) {
        currentAngle = 0f
    } else {
        currentAngle += -90f
    }
    val viewState = cropViewImage.saveState()
    cropViewImage.restoreState(viewState)
    val bitmap = cropViewImage.viewBitmap.rotate(-90f)
    cropViewImage.setImageBitmap(bitmap)
}

`

fun Bitmap.rotate(degrees: Float): Bitmap {
    val matrix = Matrix().apply { postRotate(degrees) }
    return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true)
}