每当在 recyclerview 中为 base64 图像调用 notifydatasetchanged() 时,图像就会闪烁

Image blinks whenever notifydatasetchanged() called in recyclerview for base64 image

我在我的项目中使用 glide 在回收站视图中显示图像。图像将从服务器下载,直到我将显示一个非常低分辨率的模糊图像。模糊图像是 base 64 编码图像,将转换为 byteArray 以在滑动中显示。

我的问题是每次调用 notifydatasetchanged() 函数时,base 64 解码图像都会闪烁。如何避免这种奇怪的行为?

我在同一回收器视图中从本地存储加载图像作为文件,但调用 notifydatasetchanged() 时没有闪烁问题。 仅针对模糊图像(base 64 解码位图)出现闪烁问题

我使用的是glide版本:4.8.0

//converting string to byteArray
byte[] blurImg = getBlurImageBitmap(fileDataTable.get("blurimg") as String)

//function which converts the image string to byteArray
fun getBlurImageBitmap(blurImageString : String) : ByteArray {
    val decodedBytes = Base64.decode(blurImageString, android.util.Base64.DEFAULT)
    return decodedBytes
}

//loading the byteArray into glide
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
    Glide.with(imageMessage.context)
         .load(chatMessage.fileData.blurImg)
         .transition(DrawableTransitionOptions.withCrossFade(1))
         .into(imageMessage)
}

我想避免base 64图像在glide中闪烁。

找到闪烁图像的原因。

发现只有base 64(模糊图像)编码的图像会导致闪烁问题,而本地存储的图像不会闪烁。 每次刷新数据时,Glide 都会将 base 64 编码的字符串转换为 drawable,因此会发生闪烁。而来自本地存储的位图是第一次处理并存储在LRU Cache中,所以再次刷新数据时不会加载。

在查看 glide 内部回调时发现,每当将 base 64 字符串转换为可绘制对象时,它都会将 null 作为资源发送。

解决方案是提供一个与 base 64 解码可绘制对象相同的占位符可绘制对象来滑动,这样它会在发送 null 作为资源时显示该可绘制占位符。

Drawable image = new BitmapDrawable(((ImageViewHolder) holder).imageView.getContext().getResources(), BitmapFactory.decodeByteArray(imgList.get(position), 0, imgList.get(position).length));

//Passing the converted drawable as placeholder
requestOptions.placeholder(image);


Glide.with(imageViewHolder.imageView.getContext())
               .load(imgList.get(position))  -> Passing the same base 64 string which was converted to drawable for placeholder
               .apply(requestOptions)
               .into(imageViewHolder.imageView);


So the image actually flickers but we have passed the same image as placeholder, so the flicker will not be visible to use