[iOS]CIFilter滤镜
2024-10-16 14:33:09
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // 滤镜效果
NSArray *operations = @[@"CILinearToSRGBToneCurve",
@"CIPhotoEffectChrome",
@"CIPhotoEffectFade",
@"CIPhotoEffectInstant",
@"CIPhotoEffectMono",
@"CIPhotoEffectNoir",
@"CIPhotoEffectProcess",
@"CIPhotoEffectTonal",
@"CIPhotoEffectTransfer",
@"CISRGBToneCurveToLinear",
@"CIVignetteEffect"]; CGFloat width = self.view.frame.size.width/;
CGFloat height = self.view.frame.size.height/; NSMutableArray *imageViews = [NSMutableArray arrayWithCapacity:]; for (int i = ; i < [operations count]; i++)
{
UIImageView *imageView = [[UIImageView alloc]initWithFrame:
CGRectMake(i%*width, i/*height, width, height)];
imageView.image = [UIImage imageNamed:@"timg.jpeg"];
[imageViews addObject:imageView];
[self.view addSubview:imageView];
} dispatch_async(dispatch_get_global_queue(, ),^{ NSMutableArray *images = [NSMutableArray arrayWithCapacity:]; for (int i = ; i < [operations count]; i++)
{
UIImage *image = [UIImage imageNamed:@"timg.jpeg"];
CIImage *cImage = [[CIImage alloc]initWithImage:image]; //使用资源
CIFilter *filter = [CIFilter filterWithName:operations[i]
keysAndValues:kCIInputImageKey,cImage, nil]; //使用默认参数
[filter setDefaults]; //生成上下文
CIContext*context = [CIContext contextWithOptions:nil]; //滤镜生成器输出图片
CIImage *outputimage = [filter outputImage]; //转换为UIImage
CGImageRef ref = [context createCGImage:outputimage fromRect:[outputimage extent]];
UIImage *temp = [UIImage imageWithCGImage:ref]; [images addObject:temp]; //释放
CGImageRelease(ref);
} dispatch_async(dispatch_get_main_queue(), ^{
for (int x = ; x < [images count]; x++)
{
UIImageView *imageView = imageViews[x];
imageView.image = images[x];
}
});
});
}
原图
添加滤镜后效果图
最新文章
- Logstash为什么那么慢?—— json序列化
- GJM : Python简单爬虫入门(二) [转载]
- javascript边角知识
- php socket函数详解
- jquery 之height(),innerHeight(),outerHeight()方法区别详解
- Gradle 教程:第一部分,安装【翻译】
- DTD限制XML文件
- Map,HashMap
- 倒影(box-reflect)
- ORACLE函数详解【weber出品】
- des和Rijndael加密
- 设计模式:Prototype 原型模式 - 同学你抄过别人的作业么?-clone()方法的使用
- 文本去重-----awk或者uniq
- JavaSE(十二)之IO流的字节流(一)
- Leetcode 19——Remove Nth Node From End of List
- Access text files using SQL statements by DB Query Analyzer
- 【Debug】串口发送数据时部分字节被拉长,出现帧错误,原因MCU进入低功耗模式导致串口时钟停了!
- Python项目--Scrapy框架(一)
- 使用proxy来简单的实现一个观察者
- RNN实例