Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android imageview shows greenish image

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);
like image 239
dementrock Avatar asked Jun 30 '15 19:06

dementrock


3 Answers

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);
    
like image 82
neits Avatar answered Nov 08 '22 20:11

neits


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);
like image 32
RexSplode Avatar answered Nov 08 '22 20:11

RexSplode


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(). 
like image 39
Vinod Pattanshetti Avatar answered Nov 08 '22 21:11

Vinod Pattanshetti