Android-Universal-Image-Loader icon indicating copy to clipboard operation
Android-Universal-Image-Loader copied to clipboard

EXIF Orientation bug

Open ziem opened this issue 11 years ago • 37 comments

Hello, I'm using UIL 1.9.1 in my recent project. I saw that UIL is now supporting EXIF orientation https://github.com/nostra13/Android-Universal-Image-Loader/issues/172 but I encountered issue when loading photos from SD card. In my application image is rotated by 90 degrees, but in Android gallery everything is ok.

Screens:

  • my application: http://i.imgur.com/Fm857sq.png?1
  • Android gallery: http://i.imgur.com/wWmqV1G.png?1

Code: ImageLoader.getInstance().displayImage("file:///" + currentPhotoAbsolutePath, imageView, ImageLoaderOptions.GALLERY);

public static DisplayImageOptions GALLERY = new DisplayImageOptions.Builder() .cacheInMemory(true) .build();

According to https://github.com/nostra13/Android-Universal-Image-Loader/issues/172#issuecomment-17120841 it should work because I'm loading local files.

The problem occurs on:

  • Samsung Galaxy S (Cyanogenmod 11)
  • Xperia s LT26i (Android 4.1.2)

ziem avatar Mar 04 '14 09:03 ziem

Hi, @Ziem I consider this is not an issue. Have you tried to set considerExifParams(true) and cacheOnDisc(true) to your DisplayImageOption which you use in ImageLoader.displayImage() method?

grine4ka avatar Mar 04 '14 14:03 grine4ka

You are right. I overlooked it. considerExifParams(true) solved my problem, thanks.

ziem avatar Mar 04 '14 15:03 ziem

It really helped me to solve this problem.

Thanks a lot. This is really awesome library.

swatigoel avatar Apr 09 '14 13:04 swatigoel

hi :I used the 1.9.2 jar and set considerExifParams(true) and cacheOnDisc(true) but this problem is also exist

carl1990 avatar Aug 20 '14 09:08 carl1990

@carl1990 I have the same problem

ihenk avatar Nov 13 '14 11:11 ihenk

Can you provide image URL which is displayed wrong?

nostra13 avatar Nov 16 '14 11:11 nostra13

sorry! I am in debug environment use company intranet,so the url u can not access.

carl1990 avatar Nov 16 '14 11:11 carl1990

@nostra13 http://www.bipt.edu.cn/pub/news/images/content/2014-11/20141113143629640236.jpg

ihenk avatar Nov 16 '14 11:11 ihenk

before is wrong

    public static DisplayImageOptions getDefaultDisplayImageOptions(
            Context context) {
        return new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.ic_default)
                .showImageForEmptyUri(R.drawable.ic_default)
                .showImageOnFail(R.drawable.ic_default)
                .cacheInMemory(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .displayer(
                        new RoundedBitmapDisplayer(context.getResources()
                                .getDimensionPixelSize(R.dimen.icon_rounded)))
                .build();
    }

after is right

    public static DisplayImageOptions getDefaultDisplayImageOptions(
            Context context) {
        return new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.ic_default)
                .showImageForEmptyUri(R.drawable.ic_default)
                .showImageOnFail(R.drawable.ic_default)
                .cacheInMemory(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
                .cacheOnDisk(true)
                .considerExifParams(false)
                .displayer(
                        new RoundedBitmapDisplayer(context.getResources()
                                .getDimensionPixelSize(R.dimen.icon_rounded)))
                .build();
    }

ihenk avatar Nov 16 '14 11:11 ihenk

When I set "considerExifParams (true)",the picture displayed on the phone in the wrong direction.But when I open the SD card cache files and found the picture in the right direction,this is really incredible.

After several attempts, I set "considerExifParams (false)",the picture displayed on the phone in the right direction. notes: (1) My program set the phone to force portrait. (2) Only a few pictures displayed incorrectly direction. (3) I use the jar version 1.9.3.

ihenk avatar Nov 16 '14 12:11 ihenk

@ihenk I tested your link and realized this weird behavior. It seems this image is rotated during decoding into Bitmap. I'll investigate this case.

nostra13 avatar Nov 20 '14 11:11 nostra13

I faced this issue now. I also try considerExifParams on both true and false but the image still rotate 90 degree. I use version 1.9.3. Here is my display image configure:

 mDisplayImageOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
                .bitmapConfig(Bitmap.Config.ARGB_4444)
                .considerExifParams(false)
                .build();

Can someone help me to point out the issue here?

trungp avatar May 13 '15 10:05 trungp

I also meet the problem. I'm making gallery feature, so I need to load images from MediaStore. Original image files works well when I set considerExifParams to true.(otherwise it rotated wrongly)

But when I use MediaStore.Image.Thumbnail.Data, the Image rotated wrongly even though I set considerExifParams to true.

I also set cacheOnDisk, but it doesn't solve the problem.

vivaladiem avatar May 19 '15 13:05 vivaladiem

To make gallery for images, I am using below code to query Media Store: final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID, MediaStore.Images.Media.MIME_TYPE, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.SIZE}; final String orderBy = MediaStore.Images.Media._ID; Cursor imageCursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy); if (imageCursor != null && imageCursor.getCount() > 0) {

                while (imageCursor.moveToNext()) {
                    CustomGalleryItem item = new CustomGalleryItem();

                    int dataColumnIndex = imageCursor
                            .getColumnIndex(MediaStore.Images.Media.DATA);

                    item.sdcardPath = imageCursor.getString(dataColumnIndex);

                    int mimeTypeColumnIndex = imageCursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE);
                    item.mimeType = imageCursor.getString(mimeTypeColumnIndex);

                    int idColumnIndex = imageCursor.getColumnIndex(MediaStore.Images.Media._ID);
                    item.id = imageCursor.getString(idColumnIndex);

                    int nameColumnIndex = imageCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME);
                    item.fileName = imageCursor.getString(nameColumnIndex);

                    int sizeColumnIndex = imageCursor.getColumnIndex(MediaStore.Images.Media.SIZE);
                    item.fileSize = imageCursor.getString(sizeColumnIndex);

                    if(selectedList != null && selectedList.size() > 0) {
                        for(CustomGalleryItem selectedItem : selectedList) {
                            if(selectedItem.id.equals(item.id)) {
                                item.isSeleted = true;
                                break;
                            }
                        }
                    }
                    galleryList.add(item);
                }
            }

To initialize Image Loader, I have used below code:

DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) .bitmapConfig(Bitmap.Config.RGB_565) .considerExifParams(true).build(); ImageDecoder smartUriDecoder = new SmartUriDecoder(this, getContentResolver(), new BaseImageDecoder(false));

    ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(
            this).defaultDisplayImageOptions(defaultOptions).memoryCache(
                    new WeakMemoryCache())
                    .imageDecoder(smartUriDecoder);

    ImageLoaderConfiguration config = builder.build();
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.init(config);

I have written custom ImageDecoder because Universal Image loader works properly to show image thumbnail. But I wanted to show thumbnail for videos, audios as well.

I am using "universal-image-loader-1.9.2-SNAPSHOT-with-sources"

swatigoel avatar May 20 '15 04:05 swatigoel

The same issue for me. Both .considerExifParams(false) and .considerExifParams(true)

leads to the same result - not properly rotated photo for portrait made images. Landscape photo is shown properly.

universal-image-loader:1.9.4

antonderevyanko avatar Jun 10 '15 12:06 antonderevyanko

Hello i faced the problem in U.I.L. V-1.9.4.Please share the findings and fix the bug.I think it is one of the major bug of this library as they offered that feature with a heavy note.

RubydulAhsan avatar Jun 15 '15 10:06 RubydulAhsan

Until the problem is fixed, I used Picasso. It automatically solves this.

Cedriga avatar Jun 15 '15 17:06 Cedriga

@Cedriga The Picasso has the same problem in SAMSUNG NOTE III with android 4.4

carl1990 avatar Jun 24 '15 02:06 carl1990

Actually .considerExifParams(true) works for me. However make sure that you setup options and pass them to ImageLoader on any activity where you display images, Gallery, ImageDetail etc... Here is my code:

DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.blank)
                .showImageForEmptyUri(R.drawable.blank)
                .showImageOnFail(R.drawable.blank)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .build();

imageLoader.displayImage(GalleryActivity.mThumbIds[position] ,imageView, options);

burakicel avatar Aug 20 '15 15:08 burakicel

My activity view is in landscape mode.

I am using all but still image is set rotate on image view.

options = new DisplayImageOptions.Builder() .showImageOnLoading(android.R.color.white) .showImageForEmptyUri(android.R.color.white) .showImageOnFail(android.R.color.white) .imageScaleType(ImageScaleType.EXACTLY) .cacheInMemory(true) .cacheOnDisk(true) .considerExifParams(true) .bitmapConfig(Bitmap.Config.RGB_565) .build();

The same issue for me. Both .considerExifParams(false) and .considerExifParams(true)

Dineshcg avatar Aug 24 '15 13:08 Dineshcg

It's more of a compatibility issue in KitKat, Lollipop I think. Here is another thread https://github.com/square/picasso/issues/579 I'm using Picasso and having this issue. I'll use and see if UIL gives solution.

surajdubey avatar Aug 29 '15 08:08 surajdubey

you need override the BaseImageDecoder.class and override the canDefineExifParams method,add image/png mimetype,then everything is ok

rx123rx avatar Jan 21 '16 02:01 rx123rx

Is this solved?

FireZenk avatar Apr 01 '16 07:04 FireZenk

sorry ,no...

------------------ 原始邮件 ------------------ 发件人: "Jorge Garrido";[email protected]; 发送时间: 2016年4月1日(星期五) 下午3:22 收件人: "nostra13/Android-Universal-Image-Loader"[email protected];

主题: Re: [nostra13/Android-Universal-Image-Loader] EXIF Orientation bug(#559)

Is this solved?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

dikevin0512 avatar Apr 01 '16 07:04 dikevin0512

i got the reason,that is because of mimeType in method canDefineExifParams(String imageUri, String mimeType) of the class BaseImageDecoder you should add "image/png" in this method. I did it like this,and it works.

在 2016-04-01 15:25:18,"dylan" [email protected] 写道: sorry ,no...

------------------ 原始邮件 ------------------ 发件人: "Jorge Garrido";[email protected]; 发送时间: 2016年4月1日(星期五) 下午3:22 收件人: "nostra13/Android-Universal-Image-Loader"[email protected];

主题: Re: [nostra13/Android-Universal-Image-Loader] EXIF Orientation bug(#559)

Is this solved?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

— You are receiving this because you commented. Reply to this email directly or view it on GitHub

rx123rx avatar Apr 01 '16 07:04 rx123rx

Some sample code @rx123rx ?

FireZenk avatar Apr 01 '16 07:04 FireZenk

thanks ,i try it later...

------------------ 原始邮件 ------------------ 发件人: "Monkey.D.Ren";[email protected]; 发送时间: 2016年4月1日(星期五) 下午3:42 收件人: "nostra13/Android-Universal-Image-Loader"[email protected]; 抄送: "kevin"[email protected]; 主题: Re: [nostra13/Android-Universal-Image-Loader] EXIF Orientation bug(#559)

i got the reason,that is because of mimeType in method canDefineExifParams(String imageUri, String mimeType) of the class BaseImageDecoder you should add "image/png" in this method. I did it like this,and it works.

在 2016-04-01 15:25:18,"dylan" [email protected] 写道: sorry ,no...

------------------ 原始邮件 ------------------ 发件人: "Jorge Garrido";[email protected]; 发送时间: 2016年4月1日(星期五) 下午3:22 收件人: "nostra13/Android-Universal-Image-Loader"[email protected];

主题: Re: [nostra13/Android-Universal-Image-Loader] EXIF Orientation bug(#559)

Is this solved?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

— You are receiving this because you commented. Reply to this email directly or view it on GitHub — You are receiving this because you commented. Reply to this email directly or view it on GitHub

dikevin0512 avatar Apr 01 '16 07:04 dikevin0512

private boolean canDefineExifParams(String imageUri, String mimeType) { if (mimeType == null) { return false; } return ("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType)) && (Scheme.ofUri(imageUri) == Scheme.FILE); }

because of the suffix of the pictures in the cache is .png,i just override this method like this.

在 2016-04-01 15:44:36,"Jorge Garrido" [email protected] 写道:

Some sample code @rx123rx ?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

rx123rx avatar Apr 01 '16 07:04 rx123rx

ha ha ,thanks,may i take your contact information?

------------------ 原始邮件 ------------------ 发件人: "Monkey.D.Ren";[email protected]; 发送时间: 2016年4月1日(星期五) 下午3:52 收件人: "nostra13/Android-Universal-Image-Loader"[email protected]; 抄送: "kevin"[email protected]; 主题: Re: [nostra13/Android-Universal-Image-Loader] EXIF Orientation bug(#559)

private boolean canDefineExifParams(String imageUri, String mimeType) { if (mimeType == null) { return false; } return ("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType)) && (Scheme.ofUri(imageUri) == Scheme.FILE); }

because of the suffix of the pictures in the cache is .png,i just override this method like this.

在 2016-04-01 15:44:36,"Jorge Garrido" [email protected] 写道:

Some sample code @rx123rx ?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub — You are receiving this because you commented. Reply to this email directly or view it on GitHub

dikevin0512 avatar Apr 01 '16 07:04 dikevin0512

does it work?

在 2016-04-01 15:45:42,"dylan" [email protected] 写道: thanks ,i try it later...

------------------ 原始邮件 ------------------ 发件人: "Monkey.D.Ren";[email protected]; 发送时间: 2016年4月1日(星期五) 下午3:42 收件人: "nostra13/Android-Universal-Image-Loader"[email protected]; 抄送: "kevin"[email protected]; 主题: Re: [nostra13/Android-Universal-Image-Loader] EXIF Orientation bug(#559)

i got the reason,that is because of mimeType in method canDefineExifParams(String imageUri, String mimeType) of the class BaseImageDecoder you should add "image/png" in this method. I did it like this,and it works.

在 2016-04-01 15:25:18,"dylan" [email protected] 写道: sorry ,no...

------------------ 原始邮件 ------------------ 发件人: "Jorge Garrido";[email protected]; 发送时间: 2016年4月1日(星期五) 下午3:22 收件人: "nostra13/Android-Universal-Image-Loader"[email protected];

主题: Re: [nostra13/Android-Universal-Image-Loader] EXIF Orientation bug(#559)

Is this solved?

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

— You are receiving this because you commented. Reply to this email directly or view it on GitHub — You are receiving this because you commented. Reply to this email directly or view it on GitHub

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

rx123rx avatar Apr 01 '16 08:04 rx123rx