Android image for Android shows a greenish image

This is the original image:

enter image description here

This is the displayed image using ImageView:

enter image description here

However, sometimes when the image is in the carousel, bouncing back to the image can lead to the image being displayed correctly, which is even more strange ...

This behavior is observed both on the LG G3 (Android 5.1) and on Genymotion (Android 4.4.4). I use the Glide library to load images using the decoding format ARGB_8888 :

 new GlideBuilder(this).setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); 
+6
source share
3 answers

This is resolved issue 305 . Here is a brief description:

This problem only appears with JPEG images (quality does not matter). It seems like it significantly affects RGB_565 than ARGB_8888 , so you can switch DecodeFormat to ARGB_8888 (clear the application data to see if the problem 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 deleted images) to prevent Glide images from being recompressed:

     Glide.with(this) .load(url) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(imageView); 
  • Use asBitmap () and native BitmapEncoder to always compress affected images like PNG:

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

Just in case, someone tried everything that is listed above, and none of them worked (as in my case), there is another workaround. Since the greenish color occurs during the transformation, we can avoid the transformation.

 Glide.with(context) .load(url) .dontTransform() .into(holder.productImage); 
+1
source
 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(). 
+1
source

Source: https://habr.com/ru/post/990045/


All Articles