How to using GPUImage

564 Views Asked by At

How can I use GPUImage, is there a site that explains how I can use all of its features?

I looked at some sites on the internet, only found a few lines of code. How can I use all the features I want?

1

There are 1 best solutions below

2
Mouaad Abdelghafour AITALI On BEST ANSWER

To apply the filters mentioned in your comment I've written a sample app with the following :

First you need to create a GPUImageFilterGroup in order to apply all filters mixed :

  public static GPUImageFilterGroup setAdjustment(int HueOpacity, float SaturationOpacity, int ShadowOpacity, float WarmOpacity) {
        GPUImageFilterGroup filterGroup = new GPUImageFilterGroup();
        filterGroup.addFilter(new GPUImageHueFilter(range(HueOpacity, 0.0f, 360.0f)));
        filterGroup.addFilter(new GPUImageHighlightShadowFilter(range(ShadowOpacity, 0.0f, 1.0f), range(0, 1.0f, 0.0f)));
        filterGroup.addFilter(new GPUImageWhiteBalanceFilter(range((int) WarmOpacity, 4000.0f, 8000.0f), range((int) SaturationOpacity, 0.0f, -2.0f)));
        return filterGroup;
    }


 protected static float range(int percentage, float start, float end) {
        return (((end - start) * ((float) percentage)) / 100.0f) + start;
    }

To apply those filters to your GPUImageView :

private GPUImageView mainImageView;

//The default values
private float SaturationOpacity = 50.0f;
private float WarmOpacity = 50.0f;
private int ShadowOpacity = 0;
private int HueOpacity = 0;
mainImageView.setImage(YOUR BITMAP HERE);

Create 3 SeekBars for Hue, Shadow & WhiteBalance :

Hue :

seekBarHue.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean fromUser) {
                HueOpacity = i;
                mainImageView.setFilter(setAdjustment(HueOpacity,SaturationOpacity, ShadowOpacity, WarmOpacity));
               
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

Shadow :

seekBarShadow.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            ShadowOpacity = i;
            mainImageView.setFilter(setAdjustment(HueOpacity,SaturationOpacity, ShadowOpacity, WarmOpacity));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

WhiteBalance :

seekBarwarm.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                WarmOpacity = (float) i;
                mainImageView.setFilter(setAdjustment(HueOpacity,SaturationOpacity, ShadowOpacity, WarmOpacity));
            }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });