Samsung Galaxy S7 show device photos rotated

旧城冷巷雨未停 提交于 2019-12-25 08:16:07

问题


I've developed an android app that shows in an adaptor all photos the user has in its device.

This is the code I'm using to read the photos:

    Cursor photos;
    String pictureCols[] = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME };
    String order = Media.DATE_ADDED + " DESC";
    photos = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, pictureCols, null, null, order);
    photos.moveToFirst();
photosAdapter.addItems(photos);

And inside the adapter this is the code I use to show them:

    public View getView(final int position, View convertView, ViewGroup parent)
{

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View gridView;
    if (convertView == null) {
        gridView = new View(context);
        gridView = inflater.inflate(R.layout.photo_item, null);
    }
    else
    {
        gridView = (View) convertView;
    }

    photoIV = (SquareImageView)gridView.findViewById(R.id.photo);

    long photoId = photos.getLong(0);
    String thumbURL = "file://"+photos.getString(1);
    String thumbCols[] = { MediaStore.Images.Thumbnails._ID, MediaStore.Images.Thumbnails.DATA };
    Cursor thumbCursor = MediaStore.Images.Thumbnails.queryMiniThumbnail(context.getContentResolver(), photoId, Thumbnails.MINI_KIND, thumbCols);
    if(thumbCursor.getCount() > 0) {
        thumbCursor.moveToFirst();
        thumbURL = "file://"+thumbCursor.getString(1);
    }
    thumbCursor.close();

    if(!thumbURL.equals(""))
    {
       mImageOptions = new DisplayImageOptions.Builder()
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .resetViewBeforeLoading(true)
            .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
            .build();

        ImageLoader.getInstance().displayImage(thumbURL, photoIV, mImageOptions);
   }

    return gridView;
}

This code is working OK on all devices I've tested so far but some users with Samsung Galaxy S7 have reported that most of their photos are shown rotated. I cannot find any documentation related to this issue in S7. Has S7 changed something related to this? Should I read the photos in a different way to get their correct orientation? This code has been working for a long time in a lot of devices.


回答1:


If you use an image-loading library, and you care about EXIF orientation headers, choose an image-loading library that applies those headers for you (e.g., Picasso, at least for local images). This may require some sort of an opt-in call (e.g., considerExifParams(true), per your comment).

Not all images will have an EXIF orientation header. It depends on whether it is a photo, what sort of camera hardware took the photo, whether the camera app that took the photo rotated the image for you, etc.



来源:https://stackoverflow.com/questions/40010302/samsung-galaxy-s7-show-device-photos-rotated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!