Android imageview显示绿色图像 [英] Android imageview shows greenish image

查看:255
本文介绍了Android imageview显示绿色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是原始图像:

这是使用ImageView渲染的图像:

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...

在LG G3(Android 5.1)和Genymotion(Android 4.4.4)上均观察到此行为.我正在使用Glide库加载图像,并使用ARGB_8888解码格式:

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

推荐答案

这是已解决的问题 305 .快速回顾一下:

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

此问题仅在使用JPEG格式的图像时出现(质量无关紧要).看起来它对RGB_565的影响比对ARGB_8888的影响要大得多,因此您可能需要将DecodeFormat切换为ARGB_8888(清除应用程序数据以检查问题是否得到解决).但即使使用ARGB_8888,它也可能出现,因此请使用以下解决方案之一:

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. 使用DiskCacheStrategy.NONE(用于本地图像)或DiskCacheStrategy.SOURCE(用于远程图像)来防止Glide重新压缩图像:

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

  • 使用asBitmap()和自定义BitmapEncoder始终将受影响的图像压缩为PNG:

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

  • 这篇关于Android imageview显示绿色图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆