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 @   ForrestWoo  阅读(5250)  评论(2编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示