GPUImage与AVFoundation的拍照和图像处理

GPUImage的简单集成并对照片进行单滤镜处理

2017-05-09  本文已影响59人  FrankHuang93

准备工作

1、到github上下载
https://github.com/BradLarson/GPUImage
2、把GPUImage这个文件夹拖进项目中
3、在需要用到GPUimage的地方导入#import "GPUImage.h"

解释一下:这里只是展示单个滤镜对照片的处理,我为什么要用GPUImageFilterGroup这个滤镜组,因为用到多个滤镜的时候只需要改少量的代码

核心代码

    UIImage *inputImage = [UIImage imageNamed:@"timg.jpeg"]; // 原始照片
    //初始化照片类
    GPUImagePicture *imagePicture = [[GPUImagePicture alloc] initWithImage:inputImage];
    //初始化滤镜组
    self.fiterGroup = [[GPUImageFilterGroup alloc] init];
    // 曝光度滤镜
    GPUImageExposureFilter *filter1 = [GPUImageExposureFilter new];
    filter1.exposure = 2.0; // 调节曝光大小
    [self.fiterGroup addTarget:filter1]; // 把滤镜添加到滤镜组中
    [self.fiterGroup setInitialFilters:[NSArray arrayWithObject: filter1]]; // 从那个滤镜开始渲染
    [self.fiterGroup setTerminalFilter:filter1];//最终的filter
    [imagePicture addTarget:self.fiterGroup]; //把滤镜组添加到照片上
    [self.fiterGroup useNextFrameForImageCapture];
    [imagePicture processImage];
    UIImage *newImage = [self.fiterGroup imageFromCurrentFramebuffer]; // 处理过后的图片

左边原图,右边效果图

17539044-A856-4787-B828-1B9CF58FB05D.png

Demo地址("test1"方法)

https://github.com/xianchaohuang/SingleFilterPicture

上一篇 下一篇

猜你喜欢

热点阅读