使用GPUImage 实现利用GPU来实习滤镜(实时滤镜 和iphone手机一样)

一:将GPUImage 添加到工程

    两篇资料

    国外链接地址:http://code.tutsplus.com/tutorials/build-a-photo-app-with-gpuimage--mobile-12223

    国内链接地址:http://bbs.lbsweek.com/thread-1923-1-1.html 


注意:使用GPUImage 实现利用GPU来实习滤镜(实时滤镜 和iphone手机一样)_第1张图片



二:使用

   a: 图片使用滤镜

 

    GPUImageFilter *selectedFilter;

    

    switch (buttonIndex) {

        case 0:

            selectedFilter = [[GPUImageGrayscaleFilter alloc] init];

            break;

        case 1:

            selectedFilter = [[GPUImageSepiaFilter alloc] init];

            break;

        case 2:

            selectedFilter = [[GPUImageSketchFilter alloc] init];

            break;

        case 3:

            selectedFilter = [[GPUImagePixellateFilter alloc] init];

            break;

        case 4:

            selectedFilter = [[GPUImageColorInvertFilter alloc] init];

            break;

        case 5:

            selectedFilter = [[GPUImageToonFilter alloc] init];

            break;

        case 6:

            selectedFilter = [[GPUImagePinchDistortionFilter alloc] init];

            break;

        case 7:

            selectedFilter = [[GPUImageFilter alloc] init];

            break;

        default:

            break;

    }

    

    //关键代码:

    UIImage *filterImage=[selectedFilter imageByFilteringImage:self.selectImage];

    

    self.showImageView.image=filterImage;


b:实时滤镜

  

    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];

    //    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront];

    //    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionBack];

    //    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1920x1080 cameraPosition:AVCaptureDevicePositionBack];

    

    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    videoCamera.horizontallyMirrorFrontFacingCamera = NO;

    videoCamera.horizontallyMirrorRearFacingCamera = NO;

    

    filter = [[GPUImageSketchFilter alloc] init];

    GPUImageView *filterView = [[GPUImageView alloc] initWithFrame:CGRectMake(10, 100, 100, 100)];

    filterView.fillMode=kGPUImageFillModePreserveAspectRatioAndFill;

    [self.view addSubview:filterView];

    [filter addTarget:filterView];

    [videoCamera addTarget:filter];

    

    GPUImageColorInvertFilter *filter1= [[GPUImageColorInvertFilter alloc] init];

    GPUImageView *filterView1 = [[GPUImageView alloc] initWithFrame:CGRectMake(110, 100, 100, 100)];

    filterView1.fillMode=kGPUImageFillModePreserveAspectRatioAndFill;

    [self.view addSubview:filterView1];

    [filter1 addTarget:filterView1];

    [videoCamera addTarget:filter1];

    

    GPUImageGrayscaleFilter *filter2= [[GPUImageGrayscaleFilter alloc] init];

    GPUImageView *filterView2 = [[GPUImageView alloc] initWithFrame:CGRectMake(210, 100, 100, 100)];

    filterView2.fillMode=kGPUImageFillModePreserveAspectRatioAndFill;

    [self.view addSubview:filterView2];

    [filter2 addTarget:filterView2];

    [videoCamera addTarget:filter2];

    

       

    [videoCamera startCameraCapture];




你可能感兴趣的:(使用GPUImage 实现利用GPU来实习滤镜(实时滤镜 和iphone手机一样))