Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

🌱 dreaming DiNO

[Kotlin] Uri 로부터 Exif 값 얻고 설정 변경하기 본문

Android/Android Studio

[Kotlin] Uri 로부터 Exif 값 얻고 설정 변경하기

MK_____ 2022. 9. 22. 14:07
// Exif Orientation 값 확인
val exif = ExifInterface(context?.contentResolver?.openFileDescriptor(resultUri, "rw", null)!!.fileDescriptor)
val exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)

VCDebugLog.i(logTag, "before:  $exifOrientation") // 0

exif.setAttribute(ExifInterface.TAG_ORIENTATION, (ExifInterface.ORIENTATION_NORMAL).toString())
exif.saveAttributes()

val exif2 = ExifInterface(context?.contentResolver?.openFileDescriptor(resultUri, "rw", null)!!.fileDescriptor)
VCDebugLog.i(logTag, "after:  ${exif2.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)}") // 1

 

처음에는 inputStream 으로 읽어와서 saveAttributes() 를 해줬는데, Bad Error 가 나서

fileDescriptor로 읽어오는 방법으로 바꿔주었다.