GPUIMAGE中GPUImageStillCamera能够调用系统相机,并实现实时滤镜,可是我没有找到相机全屏的方法,望知道的说一下session
GPUImageStillCamera继承自GPUImageVideoCamera类,添加了捕获照片的功能。ide
GPUImageVideoCameraspa
初始化方法:code
- (id)initWithSessionPreset:(NSString *)sessionPreset cameraPosition:(AVCaptureDevicePosition)cameraPositionorm
sessionPreset是相机拍摄时的分辨率。它的值以下对象
AVCaptureSessionPresetPhoto AVCaptureSessionPresetHigh AVCaptureSessionPresetMedium AVCaptureSessionPresetLow AVCaptureSessionPreset320x240 AVCaptureSessionPreset352x288 AVCaptureSessionPreset640x480 AVCaptureSessionPreset960x540 AVCaptureSessionPreset1280x720 AVCaptureSessionPreset1920x1080 AVCaptureSessionPreset3840x2160 AVCaptureSessionPresetiFrame960x540 AVCaptureSessionPresetiFrame1280x720 AVCaptureSessionPresetInputPriority
cameraPosition相机设备,分为先后 blog
AVCaptureDevicePositionFront AVCaptureDevicePositionBack
- (void)startCameraCapture;开始捕获继承
- (void)stopCameraCapture;中止捕获ci
- (void)rotateCamera;切换先后摄像头get
添加实时滤镜
定义GPUImageStillCamera对象
mCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack]; _isBack = YES; // _mCamera.horizontallyMirrorRearFacingCamera = NO; // _mCamera.horizontallyMirrorFrontFacingCamera = YES; _mCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
定义要应用的滤镜
_mFilter = [[FWAmaroFilter alloc] init];
定义GPUImageView对象,将GPUImageStillCamera对象捕获的图像打印在GPUImageView的层。
_mGPUImgView = [[GPUImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 426)];
添加滤镜
[_mCamera addTarget:_mFilter];
添加显示
[_mFilter addTarget:_mGPUImgView];
开始捕获
[_mCamera startCameraCapture];
[self.view addSubview:_mGPUImgView];
到此为止。实时滤镜已经实现
实现拍照
-(void)takePhoto{ [_mCamera capturePhotoAsJPEGProcessedUpToFilter:_mFilter withCompletionHandler:^(NSData *processedJPEG, NSError *error){ [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:processedJPEG options:nil]; } completionHandler:^(BOOL success, NSError * _Nullable error) { }]; }]; }