attach exif data to images whenever possible

This commit is contained in:
tibbi 2017-10-21 23:19:05 +02:00
parent 1150eee2a6
commit 82d93f56d4
2 changed files with 10 additions and 1 deletions

View File

@ -37,7 +37,7 @@ android {
} }
dependencies { dependencies {
compile 'com.simplemobiletools:commons:2.30.7' compile 'com.simplemobiletools:commons:2.30.9'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
} }

View File

@ -35,6 +35,13 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
} }
val data = params[0] val data = params[0]
val tempFile = File.createTempFile("simple_temp_exif", "")
val tempFOS = FileOutputStream(tempFile)
tempFOS.use {
tempFOS.write(data)
}
val tempExif = ExifInterface(tempFile.absolutePath)
val photoFile = File(path) val photoFile = File(path)
if (activity.needsStupidWritePermissions(path)) { if (activity.needsStupidWritePermissions(path)) {
if (activity.config.treeUri.isEmpty()) { if (activity.config.treeUri.isEmpty()) {
@ -87,7 +94,9 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
if (path.startsWith(activity.internalStoragePath)) { if (path.startsWith(activity.internalStoragePath)) {
exifOrientation = getExifOrientation(totalRotation) exifOrientation = getExifOrientation(totalRotation)
} }
tempExif.copyTo(fileExif)
fileExif.setAttribute(ExifInterface.TAG_ORIENTATION, exifOrientation) fileExif.setAttribute(ExifInterface.TAG_ORIENTATION, exifOrientation)
fileExif.saveAttributes() fileExif.saveAttributes()
return photoFile.absolutePath return photoFile.absolutePath
} catch (e: Exception) { } catch (e: Exception) {