GPUimage实时滤镜的实现

  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) {
            
        }];
    }];
}

 

posted @ 2016-09-30 15:34  ForrestWoo  阅读(5242)  评论(2编辑  收藏  举报