zoukankan      html  css  js  c++  java
  • 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) {
                
            }];
        }];
    }
  • 相关阅读:
    点评cat系列-服务器开发环境部署
    [FreeRTOS].FreeRTOS CortexM3 M4中断优先级设置总结
    [FreeRTOS]FreeRTOS使用
    [Ethernet].以太网总线详解
    [USB].USB总线详解
    [CAN].CAN总线详解
    [LIN].LIN总线详解
    [SDIO].SDIO总线详解
    [eMMC]eMMC读写性能测试
    [通信]Linux User层和Kernel层常用的通信方式
  • 原文地址:https://www.cnblogs.com/salam/p/5923942.html
Copyright © 2011-2022 走看看