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

Image returned from Intent.ACTION_GET_CONTENT is not correctly rotated #566

Open
wabzqem opened this Issue Jun 24, 2014 · 25 comments

Comments

6 participants
@wabzqem
Copy link

wabzqem commented Jun 24, 2014

The images taken with my camera include exif data orientation 90. When ACTION_GET_CONTENT is used, as opposed to ACTION_PICK on KitKat, the new DocumentsActivity is shown to allow the user to choose an image. If an image is chosen from there, the image that picasso displays is not rotated correctly. You can very easily reproduce this with the following diff and running the sample app on a device with kitkat:

diff --git a/picasso-sample/src/main/java/com/example/picasso/SampleGalleryActivity.java b/picasso-sample/src/main/java/c
index 85816dc..5d2f7c2 100644
--- a/picasso-sample/src/main/java/com/example/picasso/SampleGalleryActivity.java
+++ b/picasso-sample/src/main/java/com/example/picasso/SampleGalleryActivity.java
@@ -29,8 +29,10 @@ public class SampleGalleryActivity extends PicassoSampleActivity {

     findViewById(R.id.go).setOnClickListener(new View.OnClickListener() {
       @Override public void onClick(View view) {
-        Intent gallery = new Intent(ACTION_PICK, EXTERNAL_CONTENT_URI);
-        startActivityForResult(gallery, GALLERY_REQUEST);
+        Intent intent = new Intent();
+        intent.setType("image/*");
+        intent.setAction(Intent.ACTION_GET_CONTENT);
+        startActivityForResult(intent, GALLERY_REQUEST);
       }
     });
@wabzqem

This comment has been minimized.

Copy link
Author

wabzqem commented Jun 25, 2014

The following diff fixes this issue, but I haven't done it as a pull request because I don't like it. I can't figure out a decent way to get the exif orientation from a uri given by the DocumentsProvider. Maybe someone else can. Querying for Images.ImageColumns.ORIENTATION directly on the documents uri returns 0, but if you extract the id out and use it on the MediaStore, the query returns the correct orientation.

https://gist.github.com/wabzqem/9737284e38446f8bafeb

@dnkoutso dnkoutso added this to the Picasso 2.3 milestone Jul 8, 2014

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 8, 2014

I dont see your diff being bad. I am investigating this now.

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 8, 2014

@wabzqem what device do you see this on? Is it an S5? Trying to get this to happen on a Nexus 5 and the images come back correct.

@wabzqem

This comment has been minimized.

Copy link
Author

wabzqem commented Jul 9, 2014

I'm seeing it on a Sony Xperia Z2 (D6503)

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 9, 2014

I managed to reproduce. I think I might have a DocumentBitmapHunter

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 9, 2014

Thanks. Your solution works but Picasso is on Maven with Android 4.1. Need to figure this out so I can apply the fix.

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 9, 2014

@dnkoutso dnkoutso modified the milestone: Picasso 2.3 Jul 9, 2014

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 10, 2014

First Picasso must be converted into Gradle to support latest android jar then I can fix this properly.

In the meantime use the gist provided as a transformation which is the same thing. It will rotate the bitmap and read correctly the EXIF if its a Document uri.

@kestasb

This comment has been minimized.

Copy link

kestasb commented Jul 22, 2014

The problem still exists in 2.3.3 displaying images from SD card with rotation in EXIF data. @dnkoutso suggested transformation requires API 19, so it is not suitable for me.

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 22, 2014

@kestasb I dont think you read that right.

I said that in order to fix this on Picasso level we must upgrade the library to use gradle and API Level 19.

The gist link above provides you with a solution for your orientation fix. Its a transformation for document URIs. It does the same thing.

You do not need to wait for another Picasso release to fix this.

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 22, 2014

Wait I might have been wrong. So you do not support API Level 19 in your app?

@kestasb

This comment has been minimized.

Copy link

kestasb commented Jul 22, 2014

I mean in your suggested DocumentExifTransformation class you are using DocumentsContract class which was added in API level 19 and requires this version. I support API 9+ in my app.

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 22, 2014

I updated the gist to support pre Kitkat. Can you try again?

If your app is API Level 9+ then you must take into consideration users picking an image from the documents provider instead (Kit-Kat+).

@kestasb

This comment has been minimized.

Copy link

kestasb commented Jul 23, 2014

I tried to use .transform(new DocumentExifTransformation(context, uri)) together with .centerCrop().resize(200, 150). Unfortunately, the image is loaded incorrectly cropped as without transformation.
Try yourself to load this image from SD card:
wheel

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jul 24, 2014

Let's not cannibalize another thread for this problem. Please stop posting related problems to this. This is about supporting document uris which for now can be done using the transformation, until we upgrade Picasso to use Gradle.

Having said that, there is nothing blocking you from writing your own transformation to fix the problem, which most likely is that the centerCrop() occurs before the DocumentExifTransformation.

Picasso can handle most of the normal cases but not all, but offers some easy tools to write your own and customize it. Write your own transformation that does what you want. I cant keep handholding to take care of this.

@kestasb

This comment has been minimized.

Copy link

kestasb commented Jul 24, 2014

@dnkoutso Sorry for misunderstanding, I thought you were fixing the problem I have with your library. I will try to write my own transformation though I thought it is a normal case, not a very rare situation.

@dnkoutso dnkoutso modified the milestones: Picasso Next, Picasso 2.4 Sep 6, 2014

@nicolabeghin

This comment has been minimized.

Copy link

nicolabeghin commented Jan 4, 2015

any ETA on the issue? still not working on Picasso 2.4, even with DocumentExifTransformation.
My URI is like this:

file:///storage/emulated/0/Pictures/MyApp_20150104_225326.jpg

called like this

Picasso.with(container.getContext()).load(files.get(position)).fit().skipMemoryCache().transform(new DocumentExifTransformation(container.getContext(), uri)).placeholder(R.drawable.ic_action_picture).error(R.drawable.ic_action_error).into(photo);

and get this logcat error

java.lang.IllegalArgumentException: Not a document: file:///storage/emulated/0/Pictures/MyApp_20150104_225326.jpg

btw, your library rocks!

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jan 4, 2015

How comes it doesnt work without it? Can you debug the transformation?

We can't have this yet until we upgrade Picasso to use Gradle so we can use API Level 21. There is probably a workaround for us but for now we are waiting.

@nicolabeghin

This comment has been minimized.

Copy link

nicolabeghin commented Jan 4, 2015

Thanks a lot for your super fast reply. I'm already using gradle for Picasso import (just switched from Eclipse..). Edited my previous comment with the error. Just to know if I have to exclude using Picasso to load local images (no big fuss, Picasso already managed to solve many other issues)

    compile 'com.squareup.picasso:picasso:2.4.0'
@JakeWharton

This comment has been minimized.

Copy link
Collaborator

JakeWharton commented Jan 4, 2015

That's not what he meant by using Gradle.

On Sun Jan 04 2015 at 3:02:14 PM nicolabeghin notifications@github.com
wrote:

Thanks a lot for your super fast reply. I'm already using gradle for
Picasso import (just switched from Eclipse..). edited my previous comment
with the error. Just to know if I have to exclude using Picasso to load
local images (no big fuss, Picasso already managed to solve many other
issues)

compile 'com.squareup.picasso:picasso:2.4.0'


Reply to this email directly or view it on GitHub
#566 (comment).

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jan 4, 2015

I meant building the actual library with Gradle. Not consuming it through Gradle. Without it we can't have a built-in solution for Document URIs and rotations. The transformation provided is a workaround.

@nicolabeghin

This comment has been minimized.

Copy link

nicolabeghin commented Jan 4, 2015

thanks a lot. I didn't know the build process had an influence on it, I just switched to Gradle and Android Studio. So you mean that with the transformation provided it should work with local images, is that right? I can't get my head around this, I just would like to know if that's a drop-in workaround or I need to work on the DocumentExifTransformation

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Jan 4, 2015

You need to debug DocumentExifTransformation and see what is wrong and why it doesn't rotate the image. My guess is the URI provides no data for the exif rotation to use. If you believe there is a bug please request an update on the gist.

@dnkoutso dnkoutso modified the milestones: Picasso 2.5.1, Picasso Next Feb 12, 2015

@dnkoutso

This comment has been minimized.

Copy link
Collaborator

dnkoutso commented Feb 12, 2015

We are moving to Gradle so we can finally tackle this in the code itself rather than using a custom Transformation.

@mittalnitin19951

This comment has been minimized.

Copy link

mittalnitin19951 commented Oct 3, 2015

I want to select an image from gallery and then crop it using inbuilt android crop and then save image to predefined image view that means according to that size only ,image should not become blur and want to do this with picasso ,plz help

@JakeWharton JakeWharton removed this from the Picasso Next milestone Mar 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment