-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Gif previews/thumbnails #749
Comments
Uhmm, I think it's: Glide
.with(context)
.load(gifUrl)
.thumbnail(Glide
.with(context)
.load(gifUrl)
.asBitmap()
)
.into(imageView)
; or in case you just meant thumbnails as small images in a list, just use |
Using Glide.with(mContext)
.load(URL)
.thumbnail(Glide.with(mContext).load(URL).asBitmap())
.into(imageView); like you posted above gives a:
Adding just a .asBitmap after .load and omitting the thumbnail code seems to work for loading the first frame, but im guessing it downloads the entire gif first before displaying the first frame, as I just tested with a couple gifs and some of the previews didnt load for a good 7+ seconds, which isnt useful in a list. Is there a reason for this, or a way to do this better? |
Huh, sorry, I thought bitmap thumbs are handled (see #107), I wrote the code on my phone. Here's a compiling one which should also display much-much faster (see #281 and related issues): Glide
.with(context)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.thumbnail(Glide
.with(context)
.load(url)
.asBitmap()
.transcode(new BitmapToGlideDrawableTranscoder(context), GlideDrawable.class)
.diskCacheStrategy(DiskCacheStrategy.ALL)
)
.into(imageView)
; You can also try Hmm, thinking a little more: you may not even need the thumbnail call, because it should decode the first frame at the same speed. You may get a faster thubmnail load if you use |
Ok, so I messed around with a bunch of different configurations. None of the options I tried allowed the gifs to load fast enough to be displayed in a list, even using small gifs. The fastest configuration I found to get anything to show up in the list items was: Glide.with(mContext)
.load(URL)
// .asBitmap()
// .transcode(new BitmapToGlideDrawableTranscoder(mContext), GlideDrawable.class)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.thumbnail(Glide
.with(mContext)
.load(URL)
.asBitmap()
.transcode(new BitmapToGlideDrawableTranscoder(mContext), GlideDrawable.class)
.diskCacheStrategy(DiskCacheStrategy.NONE)
)
.into(holder.clipImageView)
; This at least gets something to show up quickly, but, they still start animating after awhile, and since its not quick enough for that id rather grab the first frame and just use that for a preview. How can i stop it from animating so that i can use just the first frame? |
Just use what you passed into thumbnail and call Also consider changing caching to |
Note that no picture loader library would be able to make the Internet faster for you :) I think the fastest trick is to decode directly from the network stream and just the first frame. |
If you have a minute, could you provide an example of what your talking about here^? If i remove the .transcode() inside the thumbnail it shows an error for the thumbnail method. Especially not sure what you mean here:
|
There are two Glide
.with(mContext)
.load(URL)
.asBitmap() // load first frame only
//.transcode(new BitmapToGlideDrawableTranscoder(mContext), GlideDrawable.class)
.diskCacheStrategy(DiskCacheStrategy.RESULT) // directly from network, but save first frame to cache so next time it's faster
.listener(...) // call downloadOnly when success
.into(holder.clipImageView) |
@TWiStErRob Ok, so if im following you correctly, your saying use this correct?: Glide.with(mContext)
.load(URL)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(holder.clipImageView)
; Using NONE instead of RESULT loads the first frame about 3x faster. Is there a way to get something like Also, couldnt seems to find any docs on using |
3x: what about the next infinitely many times? |
Hmm not sure, will test in a bit. Anyway thanks! I'll probably load the static previews, and then load whatever i need in a separate activity when clicked. I'll leave this open for a bit if anybody else wants to chime in. |
Closing this as your issue seems to be resolved. |
Hi, |
Hi again, |
@KimiChiu if you use OkHttp for caching, then you're portentially duplicating files in OkHttp cache and Picasso/Glide cache unless you disable the image loaders' disk caches (Glide: As for first frame only: I think if you use |
@TWiStErRob It stop caching files occasionally after I changed the Here's what I did:
|
@KimiChiu looks like you have a good grasp over caches. Using NONE or RESULT is the way to go if you want to use OkHttp caches. My point was: if you used SOURCE/ALL cache in Glide, or whatever the equivalent in Picasso is, and also enable OkHttp cache, then if you load the same image URL in both image loaders you'll get 3 files on the device: 1 in OkHttp cache, 1 in Glide SOURCE cache, 1 in Picasso's cache. They'll be the same byte by byte.
In that use case RESULT is simply not the right strategy, ALL or SOURCE is. First load will populate the SOURCE cache and second load will use that cached version. In case of ALL you'll also get two downsized images in cache which will result in faster load times in the future. It's good for example if you show the current user's photo in 2-3 different sizes. |
I just found a download progress implementation from https://gist.github.com/TWiStErRob/08d5807e396740e52c90
And do the reloads in Glide's |
@KimiChiu Interesting approach. The problem is that the cache strategy has to be defined before the load is started, so currently this exception to control the flow is the one that works. You could try the other type of interceptor for OkHttp. Another possibility is to have the "gif" / "not gif" flag ready when you start the load; wherever you get the image urls from could provide that. |
Hey, was wondering how to get gif thumbnails working? Basically I have a recyclerview of card items containing a gif, and would like a preview image/thumbnail image of the gif to load with the view.
The text was updated successfully, but these errors were encountered: