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

Image taken from front camera gets Rotated after compression #198

Open
imdineshsingh opened this issue Apr 5, 2022 · 2 comments
Open

Image taken from front camera gets Rotated after compression #198

imdineshsingh opened this issue Apr 5, 2022 · 2 comments

Comments

@imdineshsingh
Copy link

I am getting issue, when Image is taken from front camera it gets Rotated after compression,

@TrainedPro
Copy link

Hello! Sorry i don't use kotlin so this may be unhelpful but in Python, upon performing something similar, the photo had exif rotation data. You can either get rid of that rotation data or better yet, just utilize that date so your device actually knows what the "Right side up" is.

Here is the Python code after opening it with PIL:
ImageOps.exif_transpose(img)

Hope this helps and there is a Kotlin equivalent

@ricodidan
Copy link

I am getting issue, when Image is taken from front camera it gets Rotated after compression,

You can add this code to your own class, call the function and save bitmap to file after get rotated image.

   private fun getRotateImage(photoPath: String?, bitmap: Bitmap): Bitmap? {
        val ei = ExifInterface(
            photoPath!!
        )
        val orientation = ei.getAttributeInt(
            ExifInterface.TAG_ORIENTATION,
            ExifInterface.ORIENTATION_UNDEFINED
        )
        val rotatedBitmap: Bitmap? = when (orientation) {
            ExifInterface.ORIENTATION_ROTATE_90 -> rotateImage(bitmap, 90f)
            ExifInterface.ORIENTATION_ROTATE_180 -> rotateImage(bitmap, 180f)
            ExifInterface.ORIENTATION_ROTATE_270 -> rotateImage(bitmap, 270f)
            ExifInterface.ORIENTATION_NORMAL -> bitmap
            else -> bitmap
        }
        return rotatedBitmap
    }

    private fun rotateImage(source: Bitmap, angle: Float): Bitmap? {
        val matrix = Matrix()
        matrix.postRotate(angle)
        return Bitmap.createBitmap(
            source, 0, 0, source.width, source.height,
            matrix, true
        )
    }

    val bitmap: Bitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri)
    val rotatedImage = CheckRotatedImage.getRotateImage(filePathReal, bitmap)`

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