Open dan085 opened 4 years ago
I add this and not work whe push apply
binding.floatingActionButton.setOnClickListener{
if (exifRotation == 0) {
exifRotation = 90
} else if (exifRotation == 90) {
exifRotation = 180
} else if (exifRotation == 180) {
exifRotation = 270
} else if (exifRotation == 270) {
exifRotation = 0
}
binding.cropView.rotation=exifRotation.toFloat()
binding.cropView.setAspectRatio(AspectRatio.ASPECT_INS_1_1)
viewModel.onAspectRatioChanged(AspectRatio.ASPECT_INS_1_1)
}
I add the code for the option rotation in result
private var exifRotation: Float = 0f
binding.imageBtnRotation.setOnClickListener{
if (exifRotation == 0f) {
exifRotation = 90f
} else if (exifRotation == 90f) {
exifRotation = 180f
} else if (exifRotation == 180f) {
exifRotation = 270f
} else if (exifRotation == 270f) {
exifRotation = 0f
}
binding.cropView.rotation=exifRotation
binding.cropView.setAspectRatio(AspectRatio.ASPECT_INS_1_1)
viewModel.onAspectRatioChanged(AspectRatio.ASPECT_INS_1_1)
}
fun getCroppedData(exifRotation:Float): CroppedBitmapData {
val croppedBitmapRect = getCropSizeOriginal()
if (bitmapRect.intersect(croppedBitmapRect).not()) {
return CroppedBitmapData(croppedBitmap = bitmap)
}
val cropLeft = if (croppedBitmapRect.left.roundToInt() < bitmapRect.left) {
bitmapRect.left.toInt()
} else {
croppedBitmapRect.left.roundToInt()
}
val cropTop = if (croppedBitmapRect.top.roundToInt() < bitmapRect.top) {
bitmapRect.top.toInt()
} else {
croppedBitmapRect.top.roundToInt()
}
val cropRight = if (croppedBitmapRect.right.roundToInt() > bitmapRect.right) {
bitmapRect.right.toInt()
} else {
croppedBitmapRect.right.roundToInt()
}
val cropBottom = if (croppedBitmapRect.bottom.roundToInt() > bitmapRect.bottom) {
bitmapRect.bottom.toInt()
} else {
croppedBitmapRect.bottom.roundToInt()
}
bitmap?.let {
val matrix = Matrix()
matrix.postRotate(exifRotation)
val croppedBitmap = Bitmap.createBitmap(
it, cropLeft, cropTop, cropRight - cropLeft, cropBottom - cropTop,matrix,true
)
/**
val croppedBitmap = Bitmap.createBitmap(
it, cropLeft, cropTop, cropRight - cropLeft, cropBottom - cropTop
)**/
return CroppedBitmapData(croppedBitmap = croppedBitmap)
}
throw IllegalStateException("Bitmap is null.")
}
Regards!!!
解决了没有
@dan085 Hello friend, how did you finally solve it
Its posible to incorporate button rotate image?