GPUimage实时滤镜的实现
GPUIMAGE中GPUImageStillCamera可以調(diào)用系統(tǒng)相機(jī),并實(shí)現(xiàn)實(shí)時(shí)濾鏡,但是我沒有找到相機(jī)全屏的方法,望知道的說一下
GPUImageStillCamera繼承自GPUImageVideoCamera類,添加了捕獲照片的功能。
GPUImageVideoCamera
初始化方法:
- (id)initWithSessionPreset:(NSString *)sessionPreset cameraPosition:(AVCaptureDevicePosition)cameraPosition
sessionPreset是相機(jī)拍攝時(shí)的分辨率。它的值如下
AVCaptureSessionPresetPhoto AVCaptureSessionPresetHigh AVCaptureSessionPresetMedium AVCaptureSessionPresetLow AVCaptureSessionPreset320x240 AVCaptureSessionPreset352x288 AVCaptureSessionPreset640x480 AVCaptureSessionPreset960x540 AVCaptureSessionPreset1280x720 AVCaptureSessionPreset1920x1080 AVCaptureSessionPreset3840x2160 AVCaptureSessionPresetiFrame960x540 AVCaptureSessionPresetiFrame1280x720 AVCaptureSessionPresetInputPriority?
cameraPosition相機(jī)設(shè)備,分為前后?
AVCaptureDevicePositionFront AVCaptureDevicePositionBack?
?
- (void)startCameraCapture;開始捕獲
- (void)stopCameraCapture;停止捕獲
- (void)rotateCamera;切換前后攝像頭
?
添加實(shí)時(shí)濾鏡
定義GPUImageStillCamera對象
mCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack];_isBack = YES; // _mCamera.horizontallyMirrorRearFacingCamera = NO; // _mCamera.horizontallyMirrorFrontFacingCamera = YES;_mCamera.outputImageOrientation = UIInterfaceOrientationPortrait;?
定義要應(yīng)用的濾鏡
_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];?
到此為止。實(shí)時(shí)濾鏡已經(jīng)實(shí)現(xiàn)
?
實(shí)現(xiàn)拍照
-(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) {}];}]; }?
總結(jié)
以上是生活随笔為你收集整理的GPUimage实时滤镜的实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 学习随笔二十(多媒体编程
- 下一篇: 谈谈存储软件的无锁设计