GPUImage处理图片(滤镜)

  GPUImage 是基于 GPU 处理图像的一个开源库, 提供了各种图像处理滤镜,例如调 亮度/饱和度/曝光度/白平衡/锐化等滤镜.

并且支持照相机/摄像机 的实时滤镜.

     GPUImage采用链式方式来处理画面,通过addTarget:方法为链条添加每个环节的对象,处理完一个target,就会把上一个环节处理好的图像数据传递下一个target去处理,称为GPUImage处理链.

 

https://github.com/BradLarson/GPUImage

 图片滤镜

//调整图像的对比度
- (void)changeContrast{
    //对比度
//    GPUImageContrastFilter *filter = [[GPUImageContrastFilter alloc]init];
//    filter.contrast = self.slider.value; 
     //饱和度
//    GPUImageSaturationFilter *filter = [[GPUImageSaturationFilter alloc]init];
//    filter.saturation = self.slider.value;
     //曝光度
//    GPUImageExposureFilter *filter = [[GPUImageExposureFilter alloc] init];
//    filter.exposure = self.slider.value;
     //色温(白平衡)
    GPUImageWhiteBalanceFilter *filter = [[GPUImageWhiteBalanceFilter alloc] init];
    filter.temperature = self.slider.value;
     filter.tint = 0.0;

    //设置要渲染的区域
    [filter forceProcessingAtSize:_image.size];
    
    //获取 GPU 图片
    GPUImagePicture *pic = [[GPUImagePicture alloc]initWithImage:_image];
    //添加滤镜
    [pic addTarget:filter];
    //开始渲染
    [pic processImage];
    //(需要调用一下? why?)
    [filter useNextFrameForImageCapture];
    //获取渲染后的图片
    UIImage *newImage = [filter imageFromCurrentFramebuffer];
    
    self.imageView.image = newImage;
    
    
}

  

 实时相机滤镜

//创建相机(注意:当前vc需持有camera, 否则会提前释放)
    camera = [[GPUImageVideoCamera alloc]initWithSessionPreset:AVCaptureSessionPresetHigh cameraPosition:AVCaptureDevicePositionFront];
    camera.outputImageOrientation = UIInterfaceOrientationPortrait;
    
    //创建最终预览视图 view
    GPUImageView *cameraView = [[GPUImageView alloc]initWithFrame:self.view.frame];
    [self.view insertSubview:cameraView atIndex:0];
    
 
    //创建滤镜组合: 磨皮,美白
    GPUImageFilterGroup *groupFilter = [[GPUImageFilterGroup alloc]init];
    //磨皮滤镜
    GPUImageBilateralFilter *bilateralFilter = [[GPUImageBilateralFilter alloc]init];
    [groupFilter addTarget:bilateralFilter];
    //美白滤镜
    GPUImageBrightnessFilter *brightFilter = [[GPUImageBrightnessFilter alloc]init];
    [groupFilter addTarget:brightFilter];
    //设置滤镜组链
    [bilateralFilter addTarget:brightFilter];
    [groupFilter setInitialFilters:@[bilateralFilter]];
    groupFilter.terminalFilter = brightFilter;
    //设置 GPUImage 处理链,从数据源->滤镜->最终页面效果
    [camera addTarget:groupFilter];
    [groupFilter addTarget:cameraView];
    
    //相机开始捕获
    [camera startCameraCapture];

 

 

 

参考:

//滤镜效果

http://blog.csdn.net/gaojq_ios/article/details/46926559

//实时滤镜(相机)

https://www.jianshu.com/p/b1d3ef7fdf7a

https://www.jianshu.com/p/2ce9b63ecfef 

http://blog.csdn.net/xoxo_x/article/details/58357978

博客:(总结)

 http://blog.csdn.net/xoxo_x/article/details/52695032

GPUImage 原理

http://blog.csdn.net/qq_29846663/article/details/53707482

GPUImage所有滤镜介绍

http://www.360doc.com/content/15/0907/10/19175681_497418716.shtml

 

转载于:https://www.cnblogs.com/daxueshan/p/8296689.html

你可能感兴趣的:(GPUImage处理图片(滤镜))