Android imageview shows greenish image

时间:2015-06-30 19:22:07

标签: android imageview android-glide

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

3 个答案:

答案 0 :(得分:7)

这是一个已解决的问题305。这是一个快速回顾:

此问题仅出现在JPEG格式的图像中(质量无关紧要)。看起来它比RGB_565更显着地影响ARGB_8888,因此您可能希望将DecodeFormat切换为ARGB_8888(清除应用数据以检查问题是否已解决)。但即使使用ARGB_8888也可以显示,因此请使用以下解决方案之一:

  1. 使用DiskCacheStrategy.NONE(对于本地图像)或DiskCacheStrategy.SOURCE(对于远程图像)以防止Glide重新压缩图像:

    Glide.with(this)
        .load(url)
        .diskCacheStrategy(DiskCacheStrategy.SOURCE)
        .into(imageView);
    
  2. 使用asBitmap()和自定义BitmapEncoder始终将受影响的图像压缩为PNG:

    Glide.with(this)
        .fromResource()
        .asBitmap()
        .encoder(new BitmapEncoder(Bitmap.CompressFormat.PNG,100))
        .load(R.drawable.testimg)
        .into(imageView);
    

答案 1 :(得分:2)

以防万一有人尝试了上面列出的所有内容而且没有一个有效(就像我的情况一样),还有另一种解决方法。由于在变形过程中会出现绿色,我们可以避免变形。

Glide.with(context)
     .load(url)
     .dontTransform()
     .into(holder.productImage);

答案 2 :(得分: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().