민프

[Android][Kotlin] Exif값으로 돌아간 사진을 돌려보자!! 본문

[Android]

[Android][Kotlin] Exif값으로 돌아간 사진을 돌려보자!!

민프야 2021. 10. 16. 19:14
       var bitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri)
        var inPutStream:InputStream = contentResolver.openInputStream(uri)!!


        var exif : ExifInterface? = null
        try{
            exif = ExifInterface(inPutStream)
        }catch (e: IOException){
            e.printStackTrace()
        }
        val manufacturer = exif?.getAttribute(ExifInterface.TAG_MAKE)
        val cameraModel = exif?.getAttribute(ExifInterface.TAG_MODEL)
        val orientation = when (exif?.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0)) {
            ExifInterface.ORIENTATION_ROTATE_90 -> 90
            ExifInterface.ORIENTATION_ROTATE_180 -> 180
            ExifInterface.ORIENTATION_ROTATE_270 -> 270
            else -> 0
        }
        val dateTime = exif?.getAttribute(ExifInterface.TAG_DATETIME)
        val length = exif?.getAttribute(ExifInterface.TAG_IMAGE_LENGTH)
        val width = exif?.getAttribute(ExifInterface.TAG_IMAGE_WIDTH)
        Log.d("ExifData", "model : $manufacturer")
        Log.d("ExifData", "model2 : $cameraModel")
        Log.d("ExifData", "Orientation : $orientation")
        Log.d("ExifData", "dateTime : $dateTime")
        Log.d("ExifData", "Resolution(x*y) : $width x $length")

        var after_bitmap = rotateBitmap(bitmap,orientation)
Comments