利用GPUImage自定义相机需要以下几个类:
GPUImageStillCamera 处理相机设置
GPUImageView 图片预览层
GPUImageFilter 相机添加滤镜处理
相机基本设置处理
_myCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionBack];
//竖屏方向
_myCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
//滤镜设置(伽玛线样式)
GPUImageGammaFilter *stretchDistortionFilter = [[GPUImageGammaFilter alloc] init];
self.myFilter = stretchDistortionFilter;
//图片预览处理
_imageView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
相机全屏设置
_imageView.fillMode = kGPUImageFillModeStretch;
//添加滤镜到相机上
[_myCamera addTarget:stretchDistortionFilter];
[stretchDistortionFilter addTarget:_imageView];
[self.view addSubview:_imageView];
[_myCamera startCameraCapture];
定格一张图片 保存到相册
[self.myCamera capturePhotoAsPNGProcessedUpToFilter:self.myFilter withCompletionHandler:^(NSData *processedPNG, NSError *error) {
NSLog(@"error--%@",error);
}];