项目中导入 GPUImage
GPUImage在导入工程之前,需要先在本地运行,然后将运行后的文件拖入到工程中.
(1)需要注意的是,在编译前,需要:
把 Headers文件夹下 Project 中的头文件,全部拖到 Public文件夹下面.
(2)点击Products下的 libGPUImage.a,右键, show in finder
(3)把该目录下的libGpuImage.a 和 usr文件夹拖到我们的工程中
(4)导入#import "GPUImage.h
头文件,即可使用
一些滤镜:
/**
高斯模糊
*/
- (UIImage *)imageGaussianBlurFilter{
//滤镜
GPUImageGaussianBlurFilter *disFilter = [[GPUImageGaussianBlurFilter alloc]init];
//高斯能力 size 越大效果越不明显
[disFilter forceProcessingAtSize:CGSizeMake(40, 20)];
[disFilter useNextFrameForImageCapture];
GPUImagePicture *imageSoure = [[GPUImagePicture alloc]initWithImage:self.imageView.image];
//添加滤镜
[imageSoure addTarget:disFilter];
//开始渲染
[imageSoure processImage];
//渲染后的图片
UIImage *newImage = [disFilter imageFromCurrentFramebuffer];
return newImage;
}
/**
部分高斯
*/
- (UIImage *)imageGaussianSelectiveBlurFilter{
//滤镜
GPUImageGaussianSelectiveBlurFilter *disFilter = [[GPUImageGaussianSelectiveBlurFilter alloc]init];
//渲染范围
//半径
disFilter.excludeCircleRadius = 0.3;
//圆心
disFilter.excludeCirclePoint = CGPointMake(0.1, 0.4);
//资源源
GPUImagePicture *imageSoure = [[GPUImagePicture alloc]initWithImage:self.imageView.image];
[imageSoure addTarget:disFilter];
[imageSoure processImage];
[disFilter useNextFrameForImageCapture];
//渲染后的图片
UIImage *newImage = [disFilter imageFromCurrentFramebuffer];
return newImage;
}
/*
* 怀旧
*/
- (UIImage *)imageSepiaFilter{
GPUImageSepiaFilter *gaussianBlurFilter = [[GPUImageSepiaFilter alloc] init];
[gaussianBlurFilter useNextFrameForImageCapture];
// 获取数据源
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:self.imageView.image];
// 添加上滤镜
[stillImageSource addTarget:gaussianBlurFilter];
// 开始渲染
[stillImageSource processImage];
// 获取渲染后的图片
UIImage *newImage = [gaussianBlurFilter imageFromCurrentFramebuffer];
return newImage;
}
/**
* 素描
*/
- (UIImage *)imageSketchFilter{
GPUImageSketchFilter *gaussianBlurFilter = [[GPUImageSketchFilter alloc] init];
[gaussianBlurFilter useNextFrameForImageCapture];
// 获取数据源
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc]initWithImage:self.imageView.image];
// 添加上滤镜
[stillImageSource addTarget:gaussianBlurFilter];
// 开始渲染
[stillImageSource processImage];
// 获取渲染后的图片
UIImage *newImage = [gaussianBlurFilter imageFromCurrentFramebuffer];
return newImage;
}