GPUIMAGE中GPUImageStillCamera可以調用系統相機,並實現實時濾鏡,但是我沒有找到相機全屏的方法,望知道的說一下 GPUImageStillCamera繼承自GPUImageVideoCamera類,添加了捕獲照片的功能。 GPUImageVideoCamera 初始化方法: ...
GPUIMAGE中GPUImageStillCamera可以調用系統相機,並實現實時濾鏡,但是我沒有找到相機全屏的方法,望知道的說一下
GPUImageStillCamera繼承自GPUImageVideoCamera類,添加了捕獲照片的功能。
GPUImageVideoCamera
初始化方法:
- (id)initWithSessionPreset:(NSString *)sessionPreset cameraPosition:(AVCaptureDevicePosition)cameraPosition
sessionPreset是相機拍攝時的解析度。它的值如下
AVCaptureSessionPresetPhoto
AVCaptureSessionPresetHigh
AVCaptureSessionPresetMedium
AVCaptureSessionPresetLow
AVCaptureSessionPreset320x240
AVCaptureSessionPreset352x288
AVCaptureSessionPreset640x480
AVCaptureSessionPreset960x540
AVCaptureSessionPreset1280x720
AVCaptureSessionPreset1920x1080
AVCaptureSessionPreset3840x2160
AVCaptureSessionPresetiFrame960x540
AVCaptureSessionPresetiFrame1280x720
AVCaptureSessionPresetInputPriority
cameraPosition相機設備,分為前後
AVCaptureDevicePositionFront
AVCaptureDevicePositionBack
- (void)startCameraCapture;開始捕獲
- (void)stopCameraCapture;停止捕獲
- (void)rotateCamera;切換前後攝像頭
添加實時濾鏡
定義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) { }]; }]; }