GPUImageView rendering Blank after Scroll in ListView Android

1k Views Asked by At

I am using GPUImageView component from android-gpuimage Library for displaying Images (with filtered applied on them) in my ListView.

The Images are being loaded perfectly with filters for the First time in my ListView but when i scroll down the ListView, all the Scrolled Cells are displayed Blank.

Here is the code of the getView(...) method of my custom BaseAdapter :

@Override
public View getView(int position, View convert_view, ViewGroup arg2) {
    // TODO Auto-generated method stub

    if(convert_view == null)
    {
        if(inflater == null)
            inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        convert_view = inflater.inflate( R.layout.filter_item , null);

    }

    TextView thumb_file_name_tv = (TextView) convert_view.findViewById(R.id.filter_item_thumb_tv);

    GPUImageView thumb_giv = (GPUImageView) convert_view.findViewById(R.id.filter_item_thumb_giv);

    Log.d(TAG, "Image Uri = "+imageUri);

    thumb_file_name_tv.setText(""+filterNames.get(position).toString().trim());

    thumb_giv.setFilter(new GPUImageSepiaFilter());

    thumb_giv.setImage(imageUri); // this loads image on the current thread, should be run in a thread

    thumb_giv.requestRender();

    return convert_view;

}

Please tell me what i am doing wrong here ?
Any help is highly appreciated.

2

There are 2 best solutions below

3
On BEST ANSWER

It has been a while since I used that library, but from what I remember, if you change the image in the view, you need to call deleteImage() before settings the new image.
Try calling that method before calling setImage() You might need to check if the view has an image present before you can call deleteImage() or it might throw an error.

Edit :
Add the following methods to the GPUImageView.java class of the android-gpuImage library :

public void deleteImage() 
{
 mGPUImage.deleteImage(); 
}
0
On

With the new version of GPUImage the deleteImage () method does not exist, I do the following and it worked perfectly.

@BindView(R.id.editor)
GPUImageView mEditor;

Inside the OnClick that changes the bitmap of the image, do the following:

mEditor.getGPUImage().deleteImage();
mEditor.setImage(newBitmap);

In this way I delete the previous Bitmap and I can apply the new Bitmap without any problem.