Glide: Background image loaded from cache

Created on 15 Jan 2015  路  13Comments  路  Source: bumptech/glide

Hi,
I guess, when images are loaded from cache, it sets a weird background color on a JPG wich have white background. This only happens on Samsung S3.

Thanks

bug reproducible

Most helpful comment

Thanks for the sample app, very helpful! It looks like this is just due to jpeg compression. I can reproduce this when encoding jpeg at any quality level (including 100), but not when encoding PNGs. I'll look in to this a bit more, but since we rely on the framework for encoding, there's likely not much anyone can do to fix this.

That said, there are at least two work arounds I can think of:

  1. Use DiskCacheStrategy.NONE (for local images) or DiskCacheStrategy.SOURCE (for remote images) to prevent Glide from re-compressing the images
  2. Use asBitmap() and a custom BitmapEncoder to always compress affected images as PNGs:
Glide.with(this)
    .fromResource()
    .asBitmap()
    .encoder(new BitmapEncoder(Bitmap.CompressFormat.PNG,100))
    .load(R.drawable.testimg)
    .into(imageView);

Since I don't think there's anything actionable for us in the library, I'm going to close this for now. If anyone has any other suggestions or thoughts, I'm happy to revisit. If I find anything else out I'll update this issue.

Edit: After some more experimentation, it looks like this affects RGB_565 much more significantly than ARGB_8888, so you may also want to switch the DecodeFormat to ARGB_8888 (see the Configuration wiki page).

All 13 comments

Hey, can you please help out by answering the following questions:

  • Which version of Glide?
  • Which version of Android on the S3?
  • Can you please post a screenshot of what you're talking about?
  • Could you maybe share the source image URL(s)?

Really the most helpful would be if you could reproduce it in a standalone mini app which only demonstrates this issue.

Hello.

  • I'm using the version 3.4 of Glide
  • The S3 is running Android 4.3 (actually same problem on other devices except Nexus 5 (running Android L))
  • No url, the images are loaded from res.

The images are in a ExpandableListView.
test
The "Color" on the image, is actually not the real color of the JPG, wich is White. May be a problem of the Image?
This happen only when Glide uses the image from cache, because when i remove cache from the phone settings, this problem disappear.

Are you saying the transparent sections of the images are sometimes not transparent but instead filled in with another color?

If so, if you add dontTransform() to your Glide.with(...) call and clear the cache for your application, does the problem still occur?

Yes, the transparent sections of the images are filled with another color.
If i clear the cache of the application, from the device's settings, the problem will not happen, for few time, i guess untile Glide does not load the images from the cache. Then the images keep that color.
So, I ve cleared the cache of the application and applied dontTransform() to my Glide.with(...) and the problem is still there.

Wonder why this problem wont happen in android L.

Thanks.

Any chance you can attach a sample app which reproduces the issue? It's possible this was fixed by #301, although this would be a yet unreported symptom (I've seen issues with GIF frames similar to what you describe).

Let us know if you get the chance to try a sample app.

I will provide a sample app ASAP.

Thanks.

Just to double check, you have a JPEG that you expect to be partially transparent? JPEGs don't support alpha. Are you sure the image is not a GIF or a PNG?

Image was a JPEG, and when it was loaded from the Cache by the library, its "white" color changed.

Hi. I have the same issue. I have tried using jpg as well as webp. When the image is loaded from diskcache its white background is no longe white but gray.
The issue dissapears when I disable diskCache.

Here is a sample app for testing. There is a folder with screenshots inside the project.
Image is loaded in MainActivity

https://www.dropbox.com/s/4edvuyvo7cd441k/GlideGrayBGSampleApp.rar?dl=0

Thanks for the sample app, very helpful! It looks like this is just due to jpeg compression. I can reproduce this when encoding jpeg at any quality level (including 100), but not when encoding PNGs. I'll look in to this a bit more, but since we rely on the framework for encoding, there's likely not much anyone can do to fix this.

That said, there are at least two work arounds I can think of:

  1. Use DiskCacheStrategy.NONE (for local images) or DiskCacheStrategy.SOURCE (for remote images) to prevent Glide from re-compressing the images
  2. Use asBitmap() and a custom BitmapEncoder to always compress affected images as PNGs:
Glide.with(this)
    .fromResource()
    .asBitmap()
    .encoder(new BitmapEncoder(Bitmap.CompressFormat.PNG,100))
    .load(R.drawable.testimg)
    .into(imageView);

Since I don't think there's anything actionable for us in the library, I'm going to close this for now. If anyone has any other suggestions or thoughts, I'm happy to revisit. If I find anything else out I'll update this issue.

Edit: After some more experimentation, it looks like this affects RGB_565 much more significantly than ARGB_8888, so you may also want to switch the DecodeFormat to ARGB_8888 (see the Configuration wiki page).

Hi Sjudd. Thank your for looking into the issue.
Using a custom BitmapEncoder seems like the best solution in my case for 3.x version.
Best regards

Still having this issue. Images looks little darker. Why this? Please I followed all the steps as explained by @sjudd but still having this issue!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sergeyfitis picture sergeyfitis  路  3Comments

Morteza-Rastgoo picture Morteza-Rastgoo  路  3Comments

technoir42 picture technoir42  路  3Comments

sant527 picture sant527  路  3Comments

Tryking picture Tryking  路  3Comments