版本记录
版本号 | 时间 |
---|---|
V1.0 | 2017.09.05 |
前言
GPUImage
是直接利用显卡实现视频或者图像处理的技术。感兴趣可以看上面几篇文章。
1. GPUImage解析(一) —— 基本概览(一)
2. GPUImage解析(二) —— 基本概览(二)
3. GPUImage解析(三) —— 基本概览(三)
4. GPUImage解析(四) —— 安装方法及框架介绍
5. GPUImage解析(五) —— 框架中的几个基类
6. GPUImage解析(六) —— 一个简单的实例(一)
7. GPUImage解析(七) —— 一个简单的实例结合GPUImageVideoCamera(二)
8. GPUImage解析(八) —— 一个简单的实例之多滤镜视频采集存储(三)
功能要求
实现GPUImageTiltShiftFilter
滤镜的处理效果。
功能实现
下面我们先看一下实现代码。
1. JJGPUImageTiltShiftVC.h
#import <UIKit/UIKit.h>
@interface JJGPUImageTiltShiftVC : UIViewController
@end
2. JJGPUImageTiltShiftVC.m
#import "JJGPUImageTiltShiftVC.h"
#import "GPUImage.h"
@interface JJGPUImageTiltShiftVC ()
@property (nonatomic, strong) GPUImagePicture *imagePicture;
@property (nonatomic, strong) GPUImageTiltShiftFilter *tiltShiftFilter;
@property (nonatomic, strong) GPUImageView *imageView;
@end
@implementation JJGPUImageTiltShiftVC
#pragma mark - Override Base Function
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self loadTiltShiftEffect];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.imageView];
float rate = point.y / self.imageView.frame.size.height;
[self.tiltShiftFilter setTopFocusLevel:rate - 0.1];
[self.tiltShiftFilter setBottomFocusLevel:rate + 0.1];
[self.imagePicture processImage];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.navigationController.navigationBarHidden = NO;
}
#pragma mark - Object Private Function
- (void)loadTiltShiftEffect
{
//实例化GPUImageView
GPUImageView *imageView = [[GPUImageView alloc] initWithFrame:self.view.frame];
imageView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
[self.view addSubview:imageView];
self.imageView = imageView;
//实例化GPUImagePicture
self.imagePicture = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"picture"]];
//实例化GPUImageTiltShiftFilter - 模拟倾斜移位滤镜效果
self.tiltShiftFilter = [[GPUImageTiltShiftFilter alloc] init];
self.tiltShiftFilter.blurRadiusInPixels = 40.0;
[self.tiltShiftFilter forceProcessingAtSize:imageView.sizeInPixels];
//add target
[self.imagePicture addTarget:self.tiltShiftFilter];
[self.tiltShiftFilter addTarget:imageView];
[self.imagePicture processImage];
//GPUImageContext相关的数据显示
GLint size = [GPUImageContext maximumTextureSizeForThisDevice];
GLint unit = [GPUImageContext maximumTextureUnitsForThisDevice];
GLint vector = [GPUImageContext maximumVaryingVectorsForThisDevice];
NSLog(@"%d %d %d", size, unit, vector);
}
@end
效果验证
下面我们看一下效果图和gif图。
这个效果有没有很炫很好玩呢~~
后记
未完,待续~~