import "ViewController.h"
#import "GPUImage.h"
@interface ViewController ()
{
UIImage *_inputImage;
UIImage *_outputImage;
}
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (nonatomic,strong) GPUImagePicture *picture;
@property (nonatomic,strong) GPUImageView *imageView;
@property (nonatomic,strong) GPUImageFilterPipeline *pipeline;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 图片输入源
_inputImage = [UIImage imageNamed:@"icon"];
// 初始化 picture
_picture = [[GPUImagePicture alloc] initWithImage:_inputImage smoothlyScaleOutput:YES];
// 初始化 imageView
_imageView = [[GPUImageView alloc] initWithFrame:self.iconImageView.bounds];
[self.iconImageView addSubview:_imageView];
// 使用 GPUImageFilterPipeline 添加组合滤镜
GPUImageRGBFilter *filter1 = [[GPUImageRGBFilter alloc] init];
GPUImageToonFilter *filter2 = [[GPUImageToonFilter alloc] init];
NSMutableArray *arrayTemp = [NSMutableArray array];
[arrayTemp addObject:filter2];
[arrayTemp addObject:filter1];
/**
* @author hj, 07.02 2016 14:07
*
* 初始化 pipeline
*
* @param filters 滤镜数组
* @param input 被渲染的输入源,可以是GPUImagePicture、GPUImageVideoCamera等
* @param output 渲染后的输出容器,一般是显示的视图
*
* @return GPUImageFilterPipeline的对象
*/
_pipeline = [[GPUImageFilterPipeline alloc] initWithOrderedFilters:arrayTemp input:_picture output:_imageView];
// 处理图片
[_picture processImage];
[filter1 useNextFrameForImageCapture]; // 这个filter 可以是filter1 filter2等
// 输出处理后的图片
_outputImage = [_pipeline currentFilteredFrame];
// 保存到系统相册
UIImageWriteToSavedPhotosAlbum(_outputImage, self, nil, nil);
}
@end
#import "GPUImage.h"
@interface ViewController ()
{
UIImage *_inputImage;
UIImage *_outputImage;
}
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (nonatomic,strong) GPUImagePicture *picture;
@property (nonatomic,strong) GPUImageView *imageView;
@property (nonatomic,strong) GPUImageFilterPipeline *pipeline;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 图片输入源
_inputImage = [UIImage imageNamed:@"icon"];
// 初始化 picture
_picture = [[GPUImagePicture alloc] initWithImage:_inputImage smoothlyScaleOutput:YES];
// 初始化 imageView
_imageView = [[GPUImageView alloc] initWithFrame:self.iconImageView.bounds];
[self.iconImageView addSubview:_imageView];
// 使用 GPUImageFilterPipeline 添加组合滤镜
GPUImageRGBFilter *filter1 = [[GPUImageRGBFilter alloc] init];
GPUImageToonFilter *filter2 = [[GPUImageToonFilter alloc] init];
NSMutableArray *arrayTemp = [NSMutableArray array];
[arrayTemp addObject:filter2];
[arrayTemp addObject:filter1];
/**
* @author hj, 07.02 2016 14:07
*
* 初始化 pipeline
*
* @param filters 滤镜数组
* @param input 被渲染的输入源,可以是GPUImagePicture、GPUImageVideoCamera等
* @param output 渲染后的输出容器,一般是显示的视图
*
* @return GPUImageFilterPipeline的对象
*/
_pipeline = [[GPUImageFilterPipeline alloc] initWithOrderedFilters:arrayTemp input:_picture output:_imageView];
// 处理图片
[_picture processImage];
[filter1 useNextFrameForImageCapture]; // 这个filter 可以是filter1 filter2等
// 输出处理后的图片
_outputImage = [_pipeline currentFilteredFrame];
// 保存到系统相册
UIImageWriteToSavedPhotosAlbum(_outputImage, self, nil, nil);
}
@end