单张图片处理
1.单个滤镜
//设置滤镜
[self.filter useNextFrameForImageCapture];
[self.filter forceProcessingAtSizeRespectingAspectRatio:self.image.size];
self.filter.brightness = 0.5;
// 传入要处理的图片
GPUImagePicture *picture = [[GPUImagePicture alloc] initWithImage:self.image];
// 给图片添加滤镜
[picture addTarget:self.filter];
//渲染
[picture processImage];
//从滤镜中获取图片
[self.imageView setImage:self.filter.imageFromCurrentFramebuffer];
2.滤镜组
//第一个滤镜
self.filter1 = [[GPUImageBrightnessFilter alloc] init];
self.filter1.brightness = 0.0;
//第二个滤镜
self.filter2 = [[GPUImageSaturationFilter alloc] init];
self.filter2.saturation = 1.0;
//滤镜组
self.groupFilter = [[GPUImageFilterGroup alloc] init];
[self.groupFilter addTarget:self.filter1];
[self.groupFilter addTarget:self.filter2];
[self.groupFilter forceProcessingAtSizeRespectingAspectRatio:self.image.size];
//滤镜间的依赖关系,一个滤镜处理好后再去处理下一个滤镜
[self.filter1 addTarget:self.filter2];
[self.groupFilter setInitialFilters:[NSArray arrayWithObject:self.filter1]];
[self.groupFilter setTerminalFilter:self.filter2];
//输入源
GPUImagePicture *picture = [[GPUImagePicture alloc] initWithImage:self.image];
[picture addTarget:self.groupFilter];
//处理图片并获取输出
[self.groupFilter useNextFrameForImageCapture];
[picture processImage];
[self.imageView setImage:self.groupFilter.imageFromCurrentFramebuffer];
3.美颜相机
//创建相机
self.Camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront];
self.Camera.outputImageOrientation = UIInterfaceOrientationPortrait;
//创建滤镜
self.filter = [[GPUImageSaturationFilter alloc] init];
self.filter.saturation = 1.0;
//相机上添加滤镜
[self.Camera addTarget:self.filter];
//图片处理后的输出展示
self.GPUImageView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64)];
[self.view addSubview:self.GPUImageView];
//输出结果要给显示
[self.filter addTarget:self.GPUImageView];
//开始捕获图像
[self.Camera startCameraCapture];
//拍照获取的图片
[self.Camera capturePhotoAsJPEGProcessedUpToFilter:self.filter withCompletionHandler:^(NSData *processedJPEG, NSError *error) {
}];
4.视屏录制
初始化设置
initWithMovieURL:size 视屏保存的地址和视频的大小
startRecording 开始录制
[filter addTarget:self.movieWriter] 添滤镜
[self.movieWriter startRecording] 开始录制
[self.videoCamera pauseCameraCapture]; 暂停
[self.videoCamera resumeCameraCapture]; 恢复
网友评论