Compare commits

...

1 Commits

Author SHA1 Message Date
Jamie McDonald bd544eb7d2 Save Exif data when you use the same source and destination URIs 2015-02-13 15:04:46 +01:00
2 changed files with 9 additions and 11 deletions

View File

@ -34,6 +34,7 @@ import android.provider.MediaStore;
import android.view.View;
import android.view.Window;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -420,10 +421,8 @@ public class CropImageActivity extends MonitoredActivity {
if (!IN_MEMORY_CROP) {
// In-memory crop negates the rotation
CropUtil.copyExifRotation(
CropUtil.getFromMediaUri(this, getContentResolver(), sourceUri),
CropUtil.getFromMediaUri(this, getContentResolver(), saveUri)
);
File saveFile = CropUtil.getFromMediaUri(this, getContentResolver(), saveUri);
CropUtil.saveExifRotation(saveFile, exifRotation);
}
setResultUri(saveUri);

View File

@ -68,21 +68,20 @@ class CropUtil {
return ExifInterface.ORIENTATION_UNDEFINED;
}
} catch (IOException e) {
Log.e("Error getting Exif data", e);
Log.e("Error reading Exif rotation data", e);
return 0;
}
}
public static boolean copyExifRotation(File sourceFile, File destFile) {
if (sourceFile == null || destFile == null) return false;
public static boolean saveExifRotation(File file, int exifRotation) {
if (file == null) return false;
try {
ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath());
ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath());
exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION));
ExifInterface exifDest = new ExifInterface(file.getAbsolutePath());
exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(exifRotation));
exifDest.saveAttributes();
return true;
} catch (IOException e) {
Log.e("Error copying Exif data", e);
Log.e("Error saving Exif rotation data", e);
return false;
}
}