iOS开发--GPUImage的使用

GPUImage是一个可以给图片、视频增加滤镜(filter)的库,滤镜十分丰富,有:

"GPUImageColorInvertFilter.h"
"GPUImageSaturationFilter.h"  "GPUImageContrastFilter.h" "GPUImageExposureFilter.h" "GPUImageBrightnessFilter.h"
"GPUImageLevelsFilter.h" 
"GPUImageSharpenFilter.h"
 ...

等等一百多种。

使用方法

我们从官方给的例子出发,看看如何简单地使用。(tips:请按照以下1⃣️2⃣️3⃣️4⃣️5⃣️几点)

#import "GPUImage.h"
@interface SimpleImageViewController : UIViewController
{
    GPUImagePicture *sourcePicture;//源图片
    GPUImageOutput<GPUImageInput> *sepiaFilter;//滤镜
}
#import "SimpleImageViewController.h"

- (void)loadView
{    
    GPUImageView *primaryView = [[GPUImageView alloc] initWithFrame:mainScreenFrame];
    self.view = primaryView;
    ...
    //1⃣️输入的源图片初始化
    UIImage *inputImage = [UIImage imageNamed:@"yourImage.jpg"]; 
    sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
    //2⃣️初始化滤镜, 这里选择了“倾斜”效果的滤镜
    sepiaFilter = [[GPUImageTiltShiftFilter alloc] init];
    //size设定
    [sepiaFilter forceProcessingAtSize:imageView.sizeInPixels];
    //3⃣️源图片添加目标滤镜
    [sourcePicture addTarget:sepiaFilter];
    //4⃣️滤镜(Filter)添加输出view目标,这里用了self.view作为输出
    GPUImageView *imageView = (GPUImageView *) self.view;
    [sepiaFilter addTarget:imageView];
    //5⃣️开始转换
    [sourcePicture processImage];
}

以上,就是GPUImage的简单使用步骤。
若有更好的使用方法,欢迎多多指点。

参考:

BradLarson’s GPUImage

猜你喜欢

转载自blog.csdn.net/u011494083/article/details/51544310