Glide image load mysteriously fails - android

I am using Glide in my Android app to crop and cache a bitmap that I then post to my API. I handle the threading with Anko. This is my code:
val bitmap=preview_image_view.drawable as BitmapDrawable //I previously used `preview_image_view.setDrawable` to set this image. It shows properly in the debugger!
doAsync{ //an Anko specific thing
val file= Glide.with(applicationContext).asFile().load(bitmap).apply(RequestOptions().apply{
diskCacheStrategy(DiskCacheStrategy.RESOURCE)
centerCrop()
override()
}).submit().get() //Mysterious failure on submit()
uiThread{ //another Anko specific thing
Fuel.upload(.....
I get the following error whenever I hit the submit() function
W/Glide: Load failed for android.graphics.drawable.BitmapDrawable#fb798b8 with size [400x400]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Glide gives me no causes, stack trace, etc. to help me find why this error is occuring. Any ideas as to what is causing it to fail?

I later discovered the reason for the Glide image load failure. The image I was attempting to cache exceeded the size of the Android application cache, but did not provide an informative error. Later, Glide tried to load the corrupted data (an image that had size 0), but could not.
Downsizing the image before caching it (making sure it was under the Android application cache size limit) solved the issue.

Related

Android Glide image caching: Starts new load even with preload

I am using Glide 3.8.0 in Android to prefetch the images:
Glide.with(context)
.load(imageUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.preload();
With this I see the log that shows key with resolution [-2147483648x-2147483648]
V/Engine: Started new load in 1.75375ms, key: EngineKey{https://....com/uu/api/res/1.2/15USE5cHzsN75A26JngW_Q--/YXBwaWQ9eXRhY2h5b247Zmk9c3RyaW07aD0zNjA7dz02NDA7/http://....com/c026d208260f1b9d6880604661897d28+com.bumptech.glide.signature.EmptySignature#1341382+[-2147483648x-2147483648]+''+'ImageVideoBitmapDecoder.com.bumptech.glide.load.resource.bitmap'+''+'BitmapEncoder.com.bumptech.glide.load.resource.bitmap'+'GifBitmapWrapperDrawableTranscoder.com.bumptech.glide.load.resource.transcode'+''}
And when loading the actual image view, lookup is done with different size [1224x1020]:
V/Engine: Started new load in 0.45197899999999996ms, key: EngineKey{https://....com/uu/api/res/1.2/15USE5cHzsN75A26JngW_Q--/YXBwaWQ9eXRhY2h5b247Zmk9c3RyaW07aD0zNjA7dz02NDA7/http://....com/c026d208260f1b9d6880604661897d28+com.bumptech.glide.signature.EmptySignature#1341382+[1224x1020]+''+'ImageVideoBitmapDecoder.com.bumptech.glide.load.resource.bitmap'+''+'BitmapEncoder.com.bumptech.glide.load.resource.bitmap'+'GifBitmapWrapperDrawableTranscoder.com.bumptech.glide.load.resource.transcode'+''}
If I don't want to assume the size ahead of time, how can I cache it at all?
No, you can't cache images in memory unless they're the same size, so you'll need to know size ahead of time. It also needs to be the same signature, transformation and any added options. If any of these are different, your EngineKey hashCode will be different and it'll be a cache miss.
Note I'm assuming you're talking about memory caching as that's what preload is for and that's what the logs in Engine are talking about. You'll see Started new load in Engine for a memory cache miss and Loaded resource from cache for a memory cache hit.
If it's disk caching you're looking for, it's possible it's working as you intended. You need to enable the other logging to check this, so run adb shell setprop log.tag.Glide VERBOSE and look for either Finished loading BitmapDrawable from DATA_DISK_CACHE or Finished loading BitmapDrawable from DATA_DISK_CACHE or Finished loading BitmapDrawable from RESOURCE_DISK_CACHE in your LogCat.

Picasso Library Load Error

I'm using the Picasso library to dynamically load images from an API call.
Certain urls seem to return a malformed URL, for example: "http://imagesite.com/image.1241123.gif which crashes the app.
Picasso.with(activity).load(image)
.centerCrop()
.error(R.drawable.icon01)
.resize(50, 50)
.into(icon);
Looking at the documentation, I assumed the .error() parameter would handle this, but Picasso seems to see it as a valid URL, even though it won't return an image. I've also tried using the Picasso.Builder but I continue to get the same errors. Any suggestions?
picasso don't load gif image for that you have to use Glide library.
Check this link it might help you : http://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en
and you get library from : https://github.com/bumptech/glide
error() will handle issues where the URL is well formed but for some reasons it cannot display the image.
If you have malformed url it means the problem is your data. Remember garbage in , garbage out.
Use Uri.parse() before loading it to picasso, then handle the thrown exception: better fix your data.

Picasso: Loading cached image from disk too much slow

So, I was starting my project and wants to use Picasso in my project because its popular and used by many projects out there.
I included picasso using gradle and tried loading facebook profile url with this. http://graph.facebook.com/rohitiskul/picture.
It worked very well. It loaded image from network without any issues. I restarted the app.(Without actually killing the process). It showed me the same image instantly cached in Memory.
But then, I killed the app (force stop) and restarted. It took almost 10+ seconds to load the image. And that image was loading from the disk when I checked in the debug logs.
My code looks like this -
In MainActivity-
Picasso.with(context)
.load("http://graph.facebook.com/rohitiskul/picture")
.into(imageView);
In application class-
Picasso picasso = new Picasso.Builder(this)
.indicatorsEnabled(true).loggingEnabled(true).build()
Picasso.setSingletonInstance(picasso);
Anyone with the similar problem? Any solution would be helpful.
I tried loading same Url with UniversalImageLoader and it was fast when fetching cached image from disk.
Edit
Earlier while playing with my app, I found out that Picasso wasn't loading the disk cached image when device was offline.
I encounter the same problem,
but find only slow for the first image, later images will be fast.
Probably it needs a warm-up (loading index cache) ?
Okay i got your problem. I have fixed it by doing this
Picasso.with(context)
.load("http://graph.facebook.com/rohitiskul/picture")
.networkPolicy(NetworkPolicy.OFFLINE)
.into(imageView, new Callback() {
#Override
public void onSuccess() { }
#Override
public void onError() {
// Try again online if cache failed
Picasso.with(context)
.load("http://graph.facebook.com/rohitiskul/picture")
.into(imageView);
}
});
Explanation:
Picasso will look for images in cache.
If it failed only then image will be downloaded over network. In your case from facebook.
This issue I had also faced earlier, with this what I understood that Picasso refer the cached image based on image name mentioned in the URL.
In your case you don't have image name in URL like 'image1.jpg'. Due to which Picasso is finding it difficult to read from cache and it downloads the image everytime
You can give a try to image containing the image name in URL and that will work
Picasso doesn't offer disk cache out of the box. Instead, it relies on an Http Cache.
Make sure you add OkHttp to your dependency list.
Add a string identifier with the stableKey method when making the request so Picasso can identify your requests and quickly load it from the cache.
Example:
Picasso.Builder(context).loggingEnabled(true).build()
.load(imageUrl)
.stableKey("myImage")
.into(imageView)

Android Picasso Reload Image from cache fail

Its been sometime I started using Picasso for Image Loading in Android. The usual scenario is , it downloads images and cache it and if later needed it retrieves from Cache.
just found this use case,
if the ImageURL ends with .(jpg,png, etc etc .....)
Ex:http://www.androidguys.com/wp-content/uploads/2014/07/android-for-wallpaper-8.png
Picasso work as expected ,
but if the imageURL's are of type
http://cloud.clubsalive.com.au/download/33/404e58cf-d890-4eaa-981e-c2f3442f9348
then its not reloading from cache , its downloading every time when the view is loaded.
Is it a normal behavior of Picasso ???
Your image is giant. Try to increase cache size. Or scale down your image

(Glide) Getting image from cache if it exists

I have trouble when I'm using Glide in my app. As I've understood, if image was downloaded once and I request image from cache from other activity, Glide must show image quick. And I got this behavior, but not in my app. Image loads very slow (about 3 seconds), although in another app it was about 0.4 second.
My code with calling Glide:
Glide.with(this)
.load(url)
.signature(new StringSignature(url))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(mHeader);
And in other activity code are same.
May you help me?
Thanks
You don't need the signature(url) part, the model (url String in your case) is already a part of the cache key.
The problem may be that your header changes size. The view size (= resulting Bitmap size) needs to be constant for a cache hit. However since you're doing ALL caching the load should still be fast. Is there anything changing in the url maybe, like a sessionid or similar? That would make the cache miss.
If the url you're loading is an animated GIF RESULT caching can be the culprit, here's a reference.

Categories

Resources