GPUimage實時濾鏡的實現

  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) {
            
        }];
    }];
}
相關文章
相關標籤/搜索