Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(camera): Properly reset orientation exif if corrected #545

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,13 @@ private Uri saveTemporaryImage(Bitmap bitmap, Uri contentUri, InputStream is) th
* @param u
*/
private void returnResult(PluginCall call, Bitmap bitmap, Uri u) {
ExifWrapper exif = ImageUtils.getExifData(getContext(), bitmap, u);
try {
bitmap = prepareBitmap(bitmap, u);
bitmap = prepareBitmap(bitmap, u, exif);
} catch (IOException e) {
call.reject(UNABLE_TO_PROCESS_IMAGE);
return;
}

ExifWrapper exif = ImageUtils.getExifData(getContext(), bitmap, u);

// Compress the final image and prepare for output to client
ByteArrayOutputStream bitmapOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, settings.getQuality(), bitmapOutputStream);
Expand Down Expand Up @@ -430,11 +428,12 @@ private Uri getTempImage(Bitmap bitmap, Uri u, ByteArrayOutputStream bitmapOutpu
* recycling the old one in the process
* @param bitmap
* @param imageUri
* @param exif
* @return
*/
private Bitmap prepareBitmap(Bitmap bitmap, Uri imageUri) throws IOException {
private Bitmap prepareBitmap(Bitmap bitmap, Uri imageUri, ExifWrapper exif) throws IOException {
if (settings.isShouldCorrectOrientation()) {
final Bitmap newBitmap = ImageUtils.correctOrientation(getContext(), bitmap, imageUri);
final Bitmap newBitmap = ImageUtils.correctOrientation(getContext(), bitmap, imageUri, exif);
bitmap = replaceBitmap(bitmap, newBitmap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,8 @@ public void copyExif(String destFile) {
destExif.saveAttributes();
} catch (Exception ex) {}
}

public void resetOrientation() {
exif.resetOrientation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ private static Bitmap transform(final Bitmap bitmap, final Matrix matrix) {
* the appropriate amount for portrait mode
* @param bitmap
* @param imageUri
* @param exif
* @return
*/
public static Bitmap correctOrientation(final Context c, final Bitmap bitmap, final Uri imageUri) throws IOException {
public static Bitmap correctOrientation(final Context c, final Bitmap bitmap, final Uri imageUri, ExifWrapper exif) throws IOException {
if (Build.VERSION.SDK_INT < 24) {
return correctOrientationOlder(c, bitmap, imageUri);
} else {
Expand All @@ -78,9 +79,7 @@ public static Bitmap correctOrientation(final Context c, final Bitmap bitmap, fi
if (orientation != 0) {
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
ExifInterface exif = new ExifInterface(imageUri.getPath());
exif.resetOrientation();
exif.saveAttributes();
return transform(bitmap, matrix);
} else {
return bitmap;
Expand Down