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

Sometimes doesn't load the image into the view on first call #395

Closed
eicm opened this issue Apr 8, 2015 · 17 comments
Closed

Sometimes doesn't load the image into the view on first call #395

eicm opened this issue Apr 8, 2015 · 17 comments
Labels

Comments

@eicm
Copy link

eicm commented Apr 8, 2015

In a PagerAdapter instantiateItem() I make the following call:

public Object instantiateItem(ViewGroup container, int position) {
    ...
    ImageView imageView = new ImageView(getActivity());
    ...
    Glide.with(getActivity()).load(path).crossFade().thumbnail(
        Glide.with(getActivity()).load(thumbPath).asBitmap()
        .transcode(new BitmapToGlideDrawableTranscoder(getActivity()), GlideDrawable.class)
    ).into(imageView);
    ...
}

Sometimes on the first call it doesn't set the image to the given imageView, but as I scroll far enough and come back it loads the image from cache for that given position which shows that the image has been cached on the first call.

What would be the reasons for not setting the image in the imageView in the first call.

@sjudd
Copy link
Collaborator

sjudd commented Apr 8, 2015

One possibility is that your view either doesn't undergo layout, or ends up with 0 width or 0 height. Glide tries to wait until you have a valid width and height before starting image loads so we know how to resize the image.

Try using override() and see if that solves the problem. If it does, then it's almost certainly a view size issue.

@vaxus
Copy link

vaxus commented Apr 8, 2015

I've had this issue too a lot recently too. My imageviews have a predefined size (90dp x 90dp, not using wrap_content).

If I back out of the listview and reload it or scroll up and down as mentioned by @eicm, the images sometimes load correctly.

I've double checked the image links and there's no issue with them either.

Note: I'm using the viewholder pattern in my adapter to load images into my listview.

Here's my adapter code:

ArrayList<Item> ItemArrayList;

if (view == null) {

    LayoutInflater inflater = (LayoutInflater) viewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    row = inflater.inflate(R.layout.item_row, viewGroup, false);
    holder = new ItemHolder(row);
    row.setTag(holder);
}

else {
    row = view;
    holder = (ItemHolder) row.getTag();
}

Glide.with(viewGroup.getContext()).load(ItemArrayList.get(position).getItemImage()).transform(new GlideCircleTransform(c)).error(R.drawable.mm_avatar).into(holder.itemImage);

@vaxus
Copy link

vaxus commented Apr 8, 2015

Quick update. After enabling adb debugging as mentioned in the docs, I am getting the following error message on failed image loads:

java.lang.IllegalStateException: Can't call reconfigure() on a recycled bitmap

Any ideas how to go about solving this?

@sjudd
Copy link
Collaborator

sjudd commented Apr 8, 2015

@vaxus that sounds like you're returning a bitmap to the bitmap pool or recycling it twice. Do you still see the error if you remove your Transformation from your load call?

@eicm
Copy link
Author

eicm commented Apr 8, 2015

@sam setting a fixed size seems to solve the problem, though I need to
verify it more.

  • on another topic loading MediaStore thumbnails using thumbnail's path and
    load() is returning considerably faster than using loadFromMediaStore() and
    using original_id of the image.

@vaxus
Copy link

vaxus commented Apr 8, 2015

@sjudd I removed the transformation from the load call and it still gives me:
java.lang.IllegalStateException: Can't call reconfigure() on a recycled bitmap

I also tried using override to set a fixed size but the error persists.

@sjudd
Copy link
Collaborator

sjudd commented Apr 9, 2015

Interesting, can you provide a stack trace? I don't see anything else obviously wrong here. I may need a sample app to look into this further...

Interesting that just using the thumbnail path is faster than loadFromMediaStore. Do you have media store thumbs for those files? If not, loadFromMediaStore will fall back to the file path. It's possible that when you don't have thumbs the queries for the thumb file path take long enough to significantly slow down the load.

@eicm
Copy link
Author

eicm commented Apr 9, 2015

I noticed my target size has bigger width and length compared to the
MINY_THUMBS width and height and that's why in loadFromMediaStore it
actually loaded down sampled version of the original images, which as you
mentioned earlier I can use override() to set the target manually.

@eicm
Copy link
Author

eicm commented Apr 9, 2015

The other thing that I noticed is that the orientation is not taken into
the account for loading MediaStore thumbnails when loaded using
loadFromMediaStore while it has been taken into the account for to rotate
the images regarding their orientation when loading original images.

@sjudd
Copy link
Collaborator

sjudd commented Apr 11, 2015

@eicm It's possible different devices behavior differently w/r/t thumbnail orientation. The code path for media store thumbs and full size images is actually the same. The only difference is that for media store thumbs, we load data from the thumb file path rather than the original image file path.

As a result, if the thumb contains exif data or is encoded with the correct orientation, we should provide a correctly rotated image.

What device/version of Android do you see incorrectly rotated thumbs on?

@eicm
Copy link
Author

eicm commented Apr 11, 2015

I'm experiencing it on all devices I have: nexus 10 4.4, nexus 9 5.0.1,
lenova 4.2 and kindle fire OS. The rotated images have orientation set in
exif and also MediaStore orientation column. What I'm doing now is to
rotate the thumbs manually in the SimpleImage call back. But it's loading
the full size images correctly. Could it be because I'm using override
(mini_width, mini_height) in loadFromMediaStore() to force it loading the
thumbnails? (My target size is bigger than android's mini thumbs, and I'm
first loading mini thumbs and then images in my target)

@sjudd
Copy link
Collaborator

sjudd commented Apr 12, 2015

I looked into this, it turns out MediaStore.Images.Thumbnails neither produces correctly oriented images nor includes the original exif orientation tag in the thumbnail.

For now you can work around this by using load(Uri) or fromUri() instead of loadFromMediaStore().

I'll try and think of sane way to pass through the original orientation...

@vaxus
Copy link

vaxus commented Apr 13, 2015

I'm unable to provide a sample app unfortunately. I tried to use Picasso just to see if I would experience similar behaviour and it seemed to work ok. I'm not getting the errors during loads. Very strange :/

@sjudd
Copy link
Collaborator

sjudd commented Apr 13, 2015

@vaxus Can you file a new issue for the IllegalStateException?

@sjudd
Copy link
Collaborator

sjudd commented Apr 13, 2015

I'm going to close this issue since I think we addressed the original problem (images aren't loading). I filed a separate issue for the media store thumbnail rotation issue (#400) and we should file another for the IllegalStateException.

@aLoyalStudent
Copy link

I have the same issues.When I load image in the listView header,the first time ,Glide not set image to imageView.when I refresh the ui,it is normal.why ? thanks.

@TWiStErRob
Copy link
Collaborator

@aLoyalStudent please open a new issue and fill in the details!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants