Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation image button #14

Open
dan085 opened this issue Jan 16, 2020 · 4 comments
Open

Rotation image button #14

dan085 opened this issue Jan 16, 2020 · 4 comments

Comments

@dan085
Copy link

dan085 commented Jan 16, 2020

Its posible to incorporate button rotate image?

@dan085 dan085 changed the title Rotation Rotation image button Jan 16, 2020
@dan085
Copy link
Author

dan085 commented Jan 16, 2020

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)



       }

@dan085
Copy link
Author

dan085 commented Jan 16, 2020

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!!!

@byron-xie
Copy link

解决了没有

@Qdafengzi
Copy link

@dan085 Hello friend, how did you finally solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants