GPUImage学习日记(1)

简介:GPUImage 是基于GPU处理图像的一个开源库,对图像处理有巨大优势。

引用方式:可直接把源码拖入项目也可直接引用静态库文件。
通过github官方介绍,简单写了个demo。大致思路如下
  • 给GPUImageStillCamera添加滤镜GPUImageSketchFilter
  • 给filter添加输出imageView 即GPUImageView
  • 最后将输出界面添加到视图即可
代码如下
@interface ViewController ()
@property(strong, nonatomic) GPUImageStillCamera *videoCamera;
@property(strong, nonatomic) GPUImageFilter *customFilter;
@property(strong, nonatomic) GPUImageView *filteredVideoView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _videoCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
    _videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    _customFilter = [[GPUImageSketchFilter alloc] init];
    _filteredVideoView = [[GPUImageView alloc] initWithFrame:self.view.bounds];
    // Add the view somewhere so it's visible
    [_videoCamera addTarget:_customFilter];
    [_customFilter addTarget:_filteredVideoView];
    [self.view addSubview:_filteredVideoView];
    [_videoCamera startCameraCapture];



    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((self.view.bounds.size.width-50)*0.5, self.view.bounds.size.height-60, 50, 50)];
    btn.layer.cornerRadius = 25;
    btn.backgroundColor = [UIColor redColor];
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(takePhoto) forControlEvents:UIControlEventTouchUpInside];


}

-(void)takePhoto{

    [_videoCamera capturePhotoAsImageProcessedUpToFilter:_customFilter withCompletionHandler:^(UIImage *processedImage, NSError *error) {

        UIImageWriteToSavedPhotosAlbum(processedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    }];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    if (error) {
        NSLog(@"保存失败");
    } else {
        NSLog(@"保存成功");
    }
}
运行结果


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值