Giter Club home page Giter Club logo

Comments (2)

TrainedPro avatar TrainedPro commented on June 10, 2024

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

from compressor.

ricodidan avatar ricodidan commented on June 10, 2024

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)`

from compressor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.