赞
踩
首先 要加载图片并转化为CIImage
CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"IMG_0160"]];
其次,创建filter滤镜
CIFilter *filterOne = [CIFilter filterWithName:@"CIPixellate"];//马赛克滤镜
NSLog(@"%@",filterOne.attributes);
[filterOne setValue:ciImage forKey:kCIInputImageKey];
[filterOne setDefaults];
CIImage *outImage = [filterOne valueForKey:kCIOutputImageKey];
CIFilter *filterTwo = [CIFilter filterWithName:@"CIHueAdjust"];//饱和度滤镜
[filterTwo setValue:outImage forKey:kCIInputImageKey];
[filterTwo setDefaults];
NSLog(@"%@",filterTwo.attributes);//打印可修改的属性
[filterTwo setValue:@(3.14) forKey:kCIInputAngleKey];//位置不能改变
CIImage *outImageTwo = [filterTwo 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(
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。