android-gpuimage icon indicating copy to clipboard operation
android-gpuimage copied to clipboard

GPUIImageView Render Blank/Black in RecyclerView after scroll

Open theGlenn opened this issue 9 years ago • 12 comments

I'm using RecyclerView to show a list of filters applied to same Image. When the view is scrolled and then get back to the the hidden item the GPUIImageViewis rendered black.

Also, the RecyclerView is inside a Fragment and while scrolling it is very laggy, I can even see some part of the activity behind the hosted fragment.

I think it the same as #164

theGlenn avatar Jul 06 '15 12:07 theGlenn

I'm facing with the same problem, did you fix it?

CongBaDo avatar Nov 10 '15 09:11 CongBaDo

I had the same problem with the black item re entering the view in a Recycler View. The only thing that seems to remove the black view is by overriding the onViewAttachedToWindow method, deleting and setting again the image of the GPUImage.

@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
    ViewHolder viewHolder = (ViewHolder) holder;
    viewHolder.gpuImage.deleteImage();
    viewHolder.gpuImage.setImage(mPicture);

    super.onViewAttachedToWindow(holder);
}

I used a GPUImage and a GLSurfaceView but I'm guessing it also work with a GPUImageView.

calimbak avatar Jan 05 '16 09:01 calimbak

calimbak is the right answer,it's a bug of gpuimage i thought

yz285131311 avatar Jan 12 '16 04:01 yz285131311

@theGlenn Hey bro, have you solved it ? I have the same situation with you to "show a list of filters applied to same Image" with a RecyclerView.

I tried the code as below in my Adapter and it seems to work for the black problem.

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.filtericon_layout, parent, false);
    ViewHolder vh = new ViewHolder(view);
    vh.setIsRecyclable(false);
    return vh;
}

But my problem is every single item looks like the same even thought the filters applied are different. I tried to set GPUImageView.setImage() the same thumbnail(Bitmap) or different Bitmap object created by Bitmap.createBitmap(thumbnail), but it doesn't work.

AssassinWayne avatar Apr 20 '17 14:04 AssassinWayne

Facing same issues! Any body found the solution ?

myinnos avatar May 16 '17 05:05 myinnos

I think I've solved it in a different way, I put the ImageView in the ViewHolder instead of GPUImageView, and then create the Bitmap with different filters by GPUImage.getBitmapWithFilterApplied(bitmap), and setBitmap to show the picture in RecyclerView.

public Bitmap getBitmapWithFilterApplied(Context context, Bitmap bitmap, Filter filter) {
    if (mImage == null) {
        mImage = new GPUImage(context.getApplicationContext());
    }
    mImage.setFilter(filter.getFilter());
    return mImage.getBitmapWithFilterApplied(bitmap);
}

Finally, remember to recycler your bitmap.

AssassinWayne avatar May 18 '17 03:05 AssassinWayne

@AssassinWayne Cool! And this solution makes recyclerview load faster! Thanks!!!

clk0115 avatar Sep 06 '17 05:09 clk0115

@AssassinWayne , @calk0115 .... Can anyone post the adapter sample on how you are achieving this please and where you guys are recycling bitmap

devrath avatar Sep 09 '17 15:09 devrath

@AssassinWayne Thank you, it works well! and scrolling faster

Seddiks avatar Jan 10 '18 23:01 Seddiks

@AssassinWayne @Seddiks can anyone post complete code here. how bitmap load faster ?

vikas-shrma avatar Oct 27 '20 11:10 vikas-shrma

@AssassinWayne Thank you, it works well! and scrolling faster

Hai, Can you please share full code here. I'm facing this issue past two past but not yet solved. Please share it here it will help

Rajkumarrmani avatar Nov 28 '20 11:11 Rajkumarrmani

@AssassinWayne Thank you, it works well! and scrolling faster

Hai, Can you please share full code here. I'm facing this issue past two past but not yet solved. Please share it here it will help

it also done from my side and i am sharing code so that anyone not to wait anmore

All code only for adapters

  1. Initialise this globally private var gpuImage : GPUImage? = null

  2. Create a method whose return type is Bitmap

    private fun getBitmapWithFilterApplied(filter: GPUImageFilter): Bitmap? { if (gpuImage == null) { gpuImage = GPUImage(cContext.applicationContext) } gpuImage?.setFilter(filter) return gpuImage?.getBitmapWithFilterApplied(ActVideoTrimmer.m_bitmap) }

  3. Add above method to image view thumbnail.setImageBitmap(getBitmapWithFilterApplied(getCurrentIndex.imageFilter!!))

Here thumbnail is the ImageView which i declare in Layout file

vikas-shrma avatar Dec 14 '20 07:12 vikas-shrma