This is the original image:
This is the rendered image using ImageView:
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);
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:
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);
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);
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);
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With