GPUImage 混合滤镜

这个问题我弄了好久,最后发现在这个包里面就有把滤镜组合起来的用法,然后我就以360旋转喷血,你懂得

 

首先在.h文件声明

GPUImagePicture * staticPicture;

GPUImageOutput * brightnessFilter;   //亮度

GPUImageOutput * contrastFilter;//对比度

NSMutableArray *arrayTemp;

UISlider *  brightnessSlider;

UISlider * contrastSlider;

在.m文件中viewDidLoad中添加如下代码

UIImage * image = [UIImage imageNamed:@"sample1.jpg"];
    staticPicture =[[GPUImagePicture alloc] initWithImage:image smoothlyScaleOutput:YES];
    
    //亮度
    brightnessFilter =[[GPUImageBrightnessFilter alloc] init];
    CGRect mainScreenFrame =[[UIScreen mainScreen] applicationFrame];
    GPUImageView * GPUView = [[GPUImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    [brightnessFilter forceProcessingAtSize:GPUView.sizeInPixels];
    self.view = GPUView;
    [brightnessFilter addTarget:GPUView];
    brightnessSlider = [[UISlider alloc] initWithFrame:CGRectMake(25.0, mainScreenFrame.size.height - 250, mainScreenFrame.size.width - 50.0, 40.0)];
    [brightnessSlider addTarget:self action:@selector(updateSliderValue:) forControlEvents:UIControlEventValueChanged];
    brightnessSlider.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    brightnessSlider.minimumValue = 0.0;
    brightnessSlider.maximumValue = 1.0;
    brightnessSlider.tag = 10;
    brightnessSlider.value = 0.0;
    [GPUView addSubview:brightnessSlider];
    [staticPicture processImage];
  //对比度
contrastFilter = [[GPUImageContrastFilter alloc]init];
    [contrastFilter forceProcessingAtSize:GPUView.sizeInPixels];
    [contrastFilter addTarget:GPUView];
    contrastSlider = [[UISlider alloc] initWithFrame:CGRectMake(25.0, mainScreenFrame.size.height - 190, mainScreenFrame.size.width - 50.0, 40.0)];
    [contrastSlider addTarget:self action:@selector(updateSliderValue:) forControlEvents:UIControlEventValueChanged];
    contrastSlider.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    contrastSlider.minimumValue = 0.0;
    contrastSlider.maximumValue = 1.0;
    contrastSlider.tag = 11;
    contrastSlider.value = 0.0;
    [GPUView addSubview:contrastSlider];
    [staticPicture processImage];




//组合,这就是把你要添加的所有滤镜效果放进数组
[staticPicture addTarget:brightnessFilter];
[staticPicture addTarget:contrastFilter];
 arrayTemp = [[NSMutableArray alloc]initWithObjects:brightnessFilter,contrastFilter,nil];
    pipeline = [[GPUImageFilterPipeline alloc]initWithOrderedFilters:arrayTemp input:staticPicture output:(GPUImageView*)self.view];

添加方法,用UISlider将调色做成可视化

- (void)updateSliderValue:(UISlider *)sender
{
    NSInteger index = sender.tag - 10;
    switch (index)
    {
        case 0:
        {
            GPUImageBrightnessFilter *GPU = (GPUImageBrightnessFilter *)brightnessFilter;
            [GPU setBrightness:brightnessSlider.value];
            [staticPicture processImage];
            NSLog(@"亮度 =  %f",brightnessSlider.value);
        }
            break;
  case 1:{
            GPUImageContrastFilter *GPU = (GPUImageContrastFilter *)contrastFilter;
            [GPU setContrast:contrastSlider.value];
            [staticPicture processImage];
            NSLog(@"对比度 =  %f",contrastSlider.value);
            
        }
        default:
            break;
    }
    
}

 

转载于:https://www.cnblogs.com/qianyindichang/p/4023717.html

你可能感兴趣的:(GPUImage 混合滤镜)