1

I am using glide in my project to show the images in recycler view. The image will be downloaded from the server until I will show a very low resolution blurred image. The blurred image is a base 64 encoded image which will converted to byteArray to show in glide.

My problem is each time when notifydatasetchanged() function is called the base 64 decoded image blinks. How to avoid this strange behaviour?

I am loading images from the local storage as File in the same recycler view, but there is no blinking problem when notifydatasetchanged() called. Only for the blurred image (base 64 decoded bitmap) blinking issue occurs

I am using glide version: 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)
}

I want to avoid the blinking of base 64 images in glide.

Zoe
  • 27,060
  • 21
  • 118
  • 148
raj abimanyu
  • 11
  • 1
  • 4
  • 1
    possible duplicate : https://stackoverflow.com/questions/37944860/why-glide-blink-the-item-imageview-when-notifydatasetchanged – Ajay Chauhan Mar 29 '19 at 08:03
  • Tried this but doesn't solve my problem. I have already used setStableIds(true) – raj abimanyu Mar 29 '19 at 08:35
  • Possible duplicate of [Why Glide blink the item ImageView when notifydatasetchanged](https://stackoverflow.com/questions/37944860/why-glide-blink-the-item-imageview-when-notifydatasetchanged) – lelloman Mar 29 '19 at 08:36
  • The solution is given for the old version of glide. Eventhough when i changed to older versions still the problem occurs – raj abimanyu Mar 29 '19 at 09:18

1 Answers1

0

Found the cause for the blinking image.

Found that only base 64 (blur image) encoded image causes the flickering issue and the image from local storage wont flicker. Glide converts the base 64 encoded string to drawable each time when the data is refreshed, so the blink happens. While the bitmap from local storage is processed for the first time and stored in LRU Cache, so it will not be loaded when the data is refreshed again.

While looking into glide internal callbacks found that it sends null as a resource whenever it converts the base 64 string into drawable.

The solution is to give a placeholder drawable same as the base 64 decoded drawable to glide so it will show that placeholder drawable whenever it sends null as a resource.

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
raj abimanyu
  • 11
  • 1
  • 4