GPUImage使用心得二:图片滤镜

主要类别

1.GPUImagePicture(图片处理)

2.GPUImageOutput(滤镜,分单个和多个之分;多个使用GPUImageFilterGroup)

下面为主要处理代码

第一:单个滤镜

//图片处理对象,self.selectImage为要处理的image

sourcePicture = [[GPUImagePicture alloc] initWithImage:self.selectImage         smoothlyScaleOutput:YES];

sepiaFilter = [[GPUImageContrastFilter alloc] init];//对比度

//

[sourcePicture addTarget:sepiaFilter];

[sourcePicture processImage];

//输出图片

UIImage *image = [sepiaGroup imageFromCurrentFramebuffer];

//设置图片

self.imageView.image= image;


第二:组合滤镜(Group)

- (void)setupDisplayFiltering;

{

    sourcePicture = [[GPUImagePicture alloc] initWithImage:self.selectImage smoothlyScaleOutput:YES];

    sepiaGroup = [[GPUImageFilterGroup alloc]init];//数组

    [sourcePicture addTarget:sepiaGroup];


    sepiaFilter = [[GPUImageContrastFilter alloc] init];//对比度

    sepiaFilter2 = [[GPUImageSaturationFilter alloc] init];//饱和度

    sepiaFilter3 = [[GPUImageExposureFilter alloc] init];//曝光

    sepiaFilter4 = [[GPUImageSharpenFilter alloc] init];//锐化

    sepiaFilter5 = [[GPUImageRGBFilter alloc] init];//RGB

//    [sepiaFilter forceProcessingAtSize:self.imageView.bounds.size]; // This is now needed to make the filter run at the smaller output size

//    [sepiaFilter2 forceProcessingAtSize:self.imageView.bounds.size]; // This is now needed to make the filter run at the smaller output size

//    [sepiaFilter3 forceProcessingAtSize:self.imageView.bounds.size]; // This is now needed to make the filter run at the smaller output size

//    [sepiaFilter4 forceProcessingAtSize:self.imageView.bounds.size]; // This is now needed to make the filter run at the smaller output size

//    [sepiaFilter5 forceProcessingAtSize:self.imageView.bounds.size]; // This is now needed to make the filter run at the smaller output size

//    [sepiaFilter6 forceProcessingAtSize:self.imageView.bounds.size]; // This is now needed to make the filter run at the smaller output size


    [self addGPUImageFilter:sepiaFilter];

    [self addGPUImageFilter:sepiaFilter2];

    [self addGPUImageFilter:sepiaFilter3];

    [self addGPUImageFilter:sepiaFilter4];

    [self addGPUImageFilter:sepiaFilter5];


    [sepiaGroup useNextFrameForImageCapture];

    [sourcePicture processImage];

    UIImage *image = [sepiaGroup imageFromCurrentFramebuffer];

    NSLog(@"image----%@",image);

    self.imageView.image= image;

}

- (void)addGPUImageFilter:(GPUImageOutput *)filter

{

    [sepiaGroupaddFilter:filter];


    GPUImageOutput *newTerminalFilter = filter;


    NSIntegercount =sepiaGroup.filterCount;


    if(count ==1)

    {

        sepiaGroup.initialFilters=@[newTerminalFilter];

        sepiaGroup.terminalFilter= newTerminalFilter;


    }else

    {

        GPUImageOutput *terminalFilter    =sepiaGroup.terminalFilter;

        NSArray*initialFilters                          =sepiaGroup.initialFilters;


        [terminalFilteraddTarget:newTerminalFilter];


        sepiaGroup.initialFilters=@[initialFilters[0]];

        sepiaGroup.terminalFilter= newTerminalFilter;

    }

}

交流可以联系:[email protected],不使用qq,只用邮箱

你可能感兴趣的:(GPUImage使用心得二:图片滤镜)