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

Translate MediaStore.Image.ORIENTATION to ExifInterface.ORIENTATION to keep orientation processing proper. #1269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.net.Uri;
import android.provider.MediaStore;
import java.io.IOException;
Expand Down Expand Up @@ -108,10 +109,21 @@ static int getExifOrientation(ContentResolver contentResolver, Uri uri) {
if (cursor == null || !cursor.moveToFirst()) {
return 0;
}
return cursor.getInt(0);

int rotation = cursor.getInt(0);
switch (rotation) {
case 90:
return ExifInterface.ORIENTATION_ROTATE_90;
case 180:
return ExifInterface.ORIENTATION_ROTATE_180;
case 270:
return ExifInterface.ORIENTATION_ROTATE_270;
default:
return ExifInterface.ORIENTATION_NORMAL;
}
} catch (RuntimeException ignored) {
// If the orientation column doesn't exist, assume no rotation.
return 0;
return ExifInterface.ORIENTATION_UNDEFINED;
} finally {
if (cursor != null) {
cursor.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.net.NetworkInfo;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -55,11 +56,13 @@ public static final class Result {
private final int exifOrientation;

public Result(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
this(checkNotNull(bitmap, "bitmap == null"), null, loadedFrom, 0);
this(checkNotNull(bitmap, "bitmap == null"), null, loadedFrom,
ExifInterface.ORIENTATION_UNDEFINED);
}

public Result(InputStream stream, Picasso.LoadedFrom loadedFrom) {
this(null, checkNotNull(stream, "stream == null"), loadedFrom, 0);
this(null, checkNotNull(stream, "stream == null"), loadedFrom,
ExifInterface.ORIENTATION_UNDEFINED);
}

Result(Bitmap bitmap, InputStream stream, Picasso.LoadedFrom loadedFrom, int exifOrientation) {
Expand Down Expand Up @@ -93,6 +96,8 @@ public Picasso.LoadedFrom getLoadedFrom() {
/**
* Returns the resulting EXIF orientation generated from a {@link #load(Request, int)} call.
* This is only accessible to built-in RequestHandlers.
*
* @return MUST return one from values defined as android.media.ExifInterface.ORIENTATION_*
*/
int getExifOrientation() {
return exifOrientation;
Expand Down