iOS中滤镜的使用(一) 马赛克滤镜
来源:互联网 发布:数控车床编程自学网 编辑:程序博客网 时间:2024/05/01 23:25
iOS中滤镜的使用(一)
马赛克滤镜
首先 要加载图片并转化为CIImage
CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"IMG_0160"]];
其次,创建filter滤镜
CIFilter *filter = [CIFilter filterWithName:@"CIPixellate"];NSLog(@"%@",filter.attributes);[filter setValue:ciImage forKey:kCIInputImageKey];[filter setDefaults];CIImage *outImage = [filter valueForKey:kCIOutputImageKey];
然后,用CIContext将滤镜中的图片渲染出来,原因,导出图片过过程中用到CGImageRef。
CIContext *context = [CIContext contextWithOptions:nil];CGImageRef cgImage = [context createCGImage:outImage fromRect:[outImage extent]];
最后,导出图片,注意内存的释放
UIImage *showImage = [UIImage imageWithCGImage:cgImage];CGImageRelease(cgImage);
剩下的工作就是加载马赛克图片了
UIImageView *imageView = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 600, 400)];imageView.image = showImage;imageView.center = self.view.center;[self.view addSubview:imageView];
而Filter的属性有如下:
总的代码如下:
//0:导入图片 CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"IMG_0160"]]; //1:创建filter滤镜 CIFilter *filter = [CIFilter filterWithName:@"CIPixellate"]; NSLog(@"%@",filter.attributes); [filter setValue:ciImage forKey:kCIInputImageKey]; [filter setDefaults]; CIImage *outImage = [filter valueForKey:kCIOutputImageKey]; //2:用CIContext将滤镜中的图片渲染出来 CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef cgImage = [context createCGImage:outImage fromRect:[outImage extent]]; //3:导出图片 UIImage *showImage = [UIImage imageWithCGImage:cgImage]; CGImageRelease(cgImage); //4:加载出来 UIImageView *imageView = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 600, 400)]; imageView.image = showImage; imageView.center = self.view.center; [self.view addSubview:imageView];
0 0
- iOS中滤镜的使用(一) 马赛克滤镜
- iOS中滤镜的使用(二)滤镜组合
- iOS中滤镜的使用(三)OpenGLES渲染
- canvas图像像素处理- 马赛克/滤镜(一)
- 马赛克滤镜效果
- 图像特效---马赛克滤镜
- Python: PS 滤镜--马赛克
- iOS使用滤镜
- Air For IOS 滤镜的使用
- cocos shader 之 马赛克滤镜
- 【PS滤镜】卷页滤镜的使用
- 减少滤镜的使用
- glow滤镜的使用
- 最小化滤镜的使用
- 【CSS滤镜的使用】
- ios 滤镜
- ios 滤镜
- iOS滤镜
- 【猪猪-前端】收集了30个div+css后台模板,方便大家日常开发使用,简洁易用一贯原则。
- CUDA介绍
- mysql表结构查询
- 极光推送 使用实例 (一)服务端
- tuple DEMO
- iOS中滤镜的使用(一) 马赛克滤镜
- IIS express 7.5 配置和多站点运行
- PCB拼板和工艺边教程
- 调用百度定位API接口例子
- android 定位的4种方式介绍
- 分析C语言的声明
- iOS7.1及以后版本企业应用发布过程中的问题及解决方案
- U-boot-2014.10移植到TQ2416开发板之NandFlash启动探究
- UIWebView 无缝切换到 WKWebView