mirror of
				https://github.com/SimpleMobileTools/Simple-Camera.git
				synced 2025-06-27 09:02:59 +02:00 
			
		
		
		
	use the functions from Commons for saving rotated images
This commit is contained in:
		@@ -45,7 +45,7 @@ ext {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
    implementation 'com.simplemobiletools:commons:3.17.21'
 | 
			
		||||
    implementation 'com.simplemobiletools:commons:3.17.22'
 | 
			
		||||
 | 
			
		||||
    debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
 | 
			
		||||
    releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
 | 
			
		||||
 
 | 
			
		||||
@@ -78,7 +78,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
 | 
			
		||||
            val imageRot = orient.degreesFromOrientation()
 | 
			
		||||
 | 
			
		||||
            val totalRotation = (imageRot + deviceRot + previewRot) % 360
 | 
			
		||||
            if (!path.startsWith(activity.internalStoragePath) && !isNougatPlus()) {
 | 
			
		||||
            if (!activity.isPathOnSD(path) && !isNougatPlus()) {
 | 
			
		||||
                image = rotate(image, totalRotation)
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -100,16 +100,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
 | 
			
		||||
            val fileExif = ExifInterface(path)
 | 
			
		||||
 | 
			
		||||
            image.compress(Bitmap.CompressFormat.JPEG, activity.config.photoQuality, fos)
 | 
			
		||||
            if (path.startsWith(activity.internalStoragePath)) {
 | 
			
		||||
                saveExifRotation(ExifInterface(path), totalRotation)
 | 
			
		||||
            } else if (isNougatPlus()) {
 | 
			
		||||
                val documentFile = activity.getSomeDocumentFile(path)
 | 
			
		||||
                if (documentFile != null) {
 | 
			
		||||
                    val parcelFileDescriptor = activity.contentResolver.openFileDescriptor(documentFile.uri, "rw")
 | 
			
		||||
                    val fileDescriptor = parcelFileDescriptor.fileDescriptor
 | 
			
		||||
                    saveExifRotation(ExifInterface(fileDescriptor), totalRotation)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            activity.saveImageRotation(path, totalRotation)
 | 
			
		||||
 | 
			
		||||
            if (activity.config.savePhotoMetadata) {
 | 
			
		||||
                tempExif.copyTo(fileExif)
 | 
			
		||||
@@ -124,13 +115,6 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
 | 
			
		||||
        return ""
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun saveExifRotation(exif: ExifInterface, degrees: Int) {
 | 
			
		||||
        val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
 | 
			
		||||
        val orientationDegrees = (orientation.degreesFromOrientation() + degrees) % 360
 | 
			
		||||
        exif.setAttribute(ExifInterface.TAG_ORIENTATION, orientationDegrees.orientationFromDegrees())
 | 
			
		||||
        exif.saveAttributes()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private fun rotate(bitmap: Bitmap, degree: Int): Bitmap? {
 | 
			
		||||
        if (degree == 0) {
 | 
			
		||||
            return bitmap
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user