如何使用 GPUImage

How to using GPUImage

如何使用 GPUImage,是否有网站解释了如何使用它的所有功能?

我看了网上的一些网站,只找到了几行代码。 我怎样才能使用我想要的所有功能?

为了应用您评论中提到的过滤器,我编写了一个示例应用程序,内容如下:

首先您需要创建一个 GPUImageFilterGroup 以便混合应用所有过滤器:

  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;
    }

将这些过滤器应用到您的 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);

为色相、阴影和白平衡创建 3 SeekBars

色调:

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) {

            }
        });

阴影:

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) {
        }
    });

白平衡:

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) {

            }
        });