bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.67k stars 6.12k forks source link

Background image loaded from cache #305

Closed LinkOut closed 9 years ago

LinkOut commented 9 years ago

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

TWiStErRob commented 9 years ago

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

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

LinkOut commented 9 years ago

Hello.

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.

sjudd commented 9 years ago

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?

LinkOut commented 9 years ago

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.

sjudd commented 9 years ago

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).

sjudd commented 9 years ago

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

LinkOut commented 9 years ago

I will provide a sample app ASAP.

Thanks.

sjudd commented 9 years ago

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?

LinkOut commented 9 years ago

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

tobalr commented 9 years ago

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

sjudd commented 9 years ago

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).

tobalr commented 9 years ago

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

giusecapo commented 7 years ago

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!