0

I have a recyclerview with cardview in it. Also having imageview, textview. I am decoding my images using Base64 decoding scheme and displaying images within the cardview.It loads the images but producing the lag effect

onBindViewHolder code

holder.iv_contestant_image.setImageBitmap(new ProcessImage().getBitmage(contestant.getContestant_image())); 

ProcessImage code

byte[] decodedString = Base64.decode(strBitmap, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return decodedByte; 

Is something wrong am I doing ?

1
  • Try to use some libraries for Image Loading. Commented Oct 27, 2016 at 5:26

3 Answers 3

1

you can use any image loading libraries. Some of libraries are Picasso Glide Fresco

Sign up to request clarification or add additional context in comments.

4 Comments

I have seen Picassso but it do not load Bitmap images
Are you trying to load from url?
No, I get a string to which I convert into byte array and do the Base64 decoding and load the image
No need to do all these thing just pass your url it will do all things for you.
0

I do believe decoding process is not instant depending on the size of the bitmap. So, try perform decoding bitmap with AsyncTask

class BitmapWorkerTask extends AsyncTask<Void, Void, Bitmap> { private final WeakReference<ImageView> imageViewReference; private String base64Img; public BitmapWorkerTask(ImageView imageView, String base64Img) { imageViewReference = new WeakReference<ImageView>(imageView); this.base64Img = base64Img; } @Override protected Bitmap doInBackground(Void... params) { byte[] decodedString = Base64.decode(base64Img, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return decodedByte; } @Override protected void onPostExecute(Bitmap bitmap) { if (imageViewReference != null && bitmap != null) { imageViewReference.get().setImageBitmap(bitmap); } } 

Inside onBindViewHolder

new BitmapWorkerTask(holder.iv_contestant_image, stringBitmap).execute(); 

2 Comments

This might cause an NPE. If the decoding is slower than the scrolling speed. Because of the View destroy and recreation.
I will try this, and the same problem I do have for cardView which having seekbar, the sliding effect lags what will be the reason for it ?
0

you can implement lazy image loading in your recycle view for fix this issue. http://blogs.innovationm.com/lazy-loading-and-memory-management-of-images-in-listview-in-android/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.