square / picasso

A powerful image downloading and caching library for Android
https://square.github.io/picasso/
Apache License 2.0
18.71k stars 3.97k forks source link

Wrong handling of EXIF rotation #1204

Open SebaZet opened 8 years ago

SebaZet commented 8 years ago

Hi Everyone,

I've just started implementing my first android app and after some research I decided to use Picasso. It is very powerfull library. So thanks for sharing this library with us.

I belive that current version of Picasso is handling EXIF information in wrong way (only for MediaStoreRequestHandler class). To be more precise:

There is method called getExifOrientation in MediaStoreRequestHandler.java file. Within this method picasso is calling query method on ContentResolver object. Picasso is passing String[] object with one item "Images.ImageColumns.ORIENTATION" as parameter for query method. According to spec (description of ORIENTATION static field in MediaStore.java file) orientation for the image is expressed as degrees (Only degrees 0, 90, 180, 270 will work). So in my opinion implementation of getExifOrientation method should "translate" degrees into values taken from EXIF spec. I changed this method like below and everything is working correctly:

static int getExifOrientation(ContentResolver contentResolver, Uri uri) { Cursor cursor = null; try { cursor = contentResolver.query(uri, CONTENT_ORIENTATION, null, null, null); if (cursor == null || !cursor.moveToFirst()) { return 0; } switch (cursor.getInt(0)) { case 90: return ExifInterface.ORIENTATION_ROTATE_90; case 180: return ExifInterface.ORIENTATION_ROTATE_180; case 270: return ExifInterface.ORIENTATION_ROTATE_270; default: return 0; // other values are not supported } } catch (RuntimeException ignored) { // If the orientation column doesn't exist, assume no rotation. return 0; } finally { if (cursor != null) { cursor.close(); } } }

Best Regards, Seba

piphagor commented 8 years ago

+1

tgolden-andplus commented 7 years ago

Not knowing a lot about the implementation on the Picasso side - is there any way a newer version could leverage the support library's ExifInterface, as described here: https://android-developers.googleblog.com/2016/12/introducing-the-exifinterface-support-library.html

We've noticed that on a few Samsung devices, image orientation doesn't seem to be respected when loading from an image file captured through the device camera.