GPUImageView setImage(bitmap) is not working correctly for second time

1.8k views Asked by At

I am developing an Photo application and i uses android GPUImageView for image edit. I want to use multiple filter. the xml portion is like

<FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <jp.co.cyberagent.android.gpuimage.GPUImageView
                android:id="@+id/gpuimage"
                android:layout_gravity="center"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY" />

            <SeekBar
                android:id="@+id/seekBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:max="100" />
        </FrameLayout>

If i use Brightness filter, change value using seekbar and show the preview at a time than next time how can i use sharpness filter on the filtered image. I set bitmap of my photo as

mGPUImageView.setImage(bitmapPhoto).

After using the filtering, get photo bitmap as

Bitmap bitmapSharpness = mGPUImageView.getGPUImage().getBitmapWithFilterApplied();

But problem is if i wanted to set the bitmapSharpness to GPUImageView the filtered color is distorted.

mGPUImageView.setImage(bitmapSharpness);

ie. sharpness preview filtered color and than again setTmage to mGPUImageView color is not same. What is the problem??

3

There are 3 answers

0
shashank singh bisht On

I had been suffering from the same problem but don't get any solution anywhere and I don't know why the git owner doesn't solve this issue but I found another way of setting the image in GPUImageView and here is the solution

I have created GPUImageView without preview and every time when I need to change the Image I just remove the old gpuImageView and create a new one like this

public void onShow() {
        if(gpuImageViewConstraintLayout.getChildCount() > 0){
            gpuImageViewConstraintLayout.removeAllViews();
        }
//        creating new GPUImageView and add layout manager in gpuImageView
        gpuImageView = new GPUImageView(activity);
        ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        gpuImageView.setLayoutParams(layoutParams);

//        create Group filter list
        filterList = createFilterList();
        gpuImageFilterGroup = new GPUImageFilterGroup(filterList);

//        set image in gpuImage view
        gpuImageView.setImage(activity.getMainBit());

//        set group Filter in gpuImageView
        gpuImageView.setFilter(gpuImageFilterGroup);

//        add gpuImageView in gpuImageViewConstraintLayout
        gpuImageViewConstraintLayout.addView(gpuImageView);

//        change the visibility of gpuImageViewConstraintLayout
        gpuImageViewConstraintLayout.setVisibility(View.VISIBLE);

//        request render
        gpuImageView.requestRender();

//        other functionality
         ....................
         ..........
         ..............
    }

public List<GPUImageFilter> createFilterList() {
        List<GPUImageFilter> filters = new ArrayList<GPUImageFilter>();
        filters.add(BRIGHTNESS_GROUP_FILTER_ITEM_NUMBER, new GPUImageBrightnessFilter(0.0f));
        filters.add(CONTRAST_GROUP_FILTER_ITEM_NUMBER, new GPUImageContrastFilter(1.0f));
        filters.add(SATURATION_GROUP_FILTER_ITEM_NUMBER, new GPUImageSaturationFilter(1.0f));
        filters.add(SHARPNESS_GROUP_FILTER_ITEM_NUMBER, new GPUImageSharpenFilter(0.0f));
        filters.add(SOFTNESS_GROUP_FILTER_ITEM_NUMBER, new GPUImageGaussianBlurFilter(0.0f));
        filters.add(TEMPERATURE_GROUP_FILTER_ITEM_NUMBER, new GPUImageTemperatureFilter(0.0f));
        filters.add(TINT_GROUP_FILTER_ITEM_NUMBER, new GPUImageTintFilter(0.0f));
        filters.add(VIBRANCE_GROUP_FILTER_ITEM_NUMBER, new GPUImageVibranceFilter(0.0f));
        filters.add(HUE_GROUP_FILTER_ITEM_NUMBER, new GPUImageHueFilter(0.0f));
        filters.add(WHITE_BALANCE_GROUP_FILTER_ITEM_NUMBER, new GPUImageWhiteBalanceFilter(5000.0f, 0.0f));
        return filters;
    }

I hope this will be helpful. here is the link to the git issue and my solution -> https://github.com/cats-oss/android-gpuimage/issues/381

0
Sabet Chowdhury On

The GPUImageView already has a filter applied on it. If you set the filtered output it will also apply that filter on the filtered output for rendering. To see the newly set bitmap with no change following code can be applied:

mGPUImageView.setFilter(new GPUImageFilter());
0
Cuong Nguyen On

Did you use GPUImageFilterGroup ? like that:

GPUImageFilterGroup mFilterGroup = new GPUImageFilterGroup();
mFilterGroup.addFilter(brightnessFilter);
mFilterGroup.addFilter(sharpnessFilter);
mGpuImage.setFilter(mFilterGroup);