6

This is the original image:

enter image description here

This is the rendered image using ImageView:

enter image description here

However, sometimes when the image is in a carousel, swiping back to the image may cause the image to render correctly, which is even more weird...

This behavior is observed both on an LG G3 (Android 5.1) and Genymotion (Android 4.4.4). I'm using the Glide library for loading images, using the ARGB_8888 decode format:

new GlideBuilder(this).setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
dementrock
  • 917
  • 3
  • 9
  • 21

3 Answers3

8

This is a resolved issue 305. Here is a quick recap:

This issue appears only with images with JPEG format (the quality is irrelevant). It looks like it affects RGB_565 much more significantly than ARGB_8888, so you may want to switch the DecodeFormat to ARGB_8888 (clear the app data to check if the issue is resolved). But it can appear even with ARGB_8888, so use one of the following solutions:

  1. Use DiskCacheStrategy.NONE (for local images) or DiskCacheStrategy.SOURCE (for remote images) to prevent Glide from re-compressing the images:

    Glide.with(this)
        .load(url)
        .diskCacheStrategy(DiskCacheStrategy.SOURCE)
        .into(imageView);
    
  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);
    
neits
  • 1,963
  • 1
  • 18
  • 32
  • Thanks, diskCacheStrategy(DiskCacheStrategy.SOURCE) is key here. All the DecodeFormat.PREFER_ARGB_8888 / GlideBuilder / GlideModule variations are useless at actually forcing 24 bit color. – Ryan Nov 11 '15 at 13:57
2

Just in case someone tried all that is listed above and none of it worked (like in my case), there is another workaround. Since greenish colour happens during transformation, we can avoid transformation.

Glide.with(context)
     .load(url)
     .dontTransform()
     .into(holder.productImage);
RexSplode
  • 1,475
  • 1
  • 16
  • 24
1
This issue may happen on few devices not all like one plus 3 or 3T and some LG devices when fetching imageUrl from server to your android project.

public static void loadImageWith(Context context, String imageUrl, ImageView imageView) {
    Glide.with(context)
            .load(imageUrl)
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .dontTransform()
            .placeholder(R.drawable.empty_photo)
            .into(imageView);
  }

centerCrop() may create issue, so avoid to use centerCrop(). 
Vinod Pattanshetti
  • 2,465
  • 3
  • 22
  • 36