• GPUImage 混合滤镜


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

    首先在.h文件声明

    GPUImagePicture * staticPicture;
    
    GPUImageOutput<GPUImageInput> * brightnessFilter;   //亮度
    
    GPUImageOutput<GPUImageInput> * 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;
        }
        
    }
  • 相关阅读:
    Java获取EXE文件图标的方法
    项目组:ouc海票票 第七周Scrum meeting会议记录
    NBear使用的注意点
    几个错误
    DataGrid列中如何去掉小数后的零
    自己看着视频的理解:设计模式之abstractfactory模式(2)
    SQL SERVER 与ACCESS、EXCEL之间的数据转换(转载)
    .NET 将文本转换成语音 (转)
    InstallShield 打包需要的几段脚本代码
    SQL2005性能分析一些细节功能你是否有用到? (转)
  • 原文地址:https://www.cnblogs.com/qianyindichang/p/4023717.html
Copyright © 2020-2023  润新知