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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM