// 对静态图像进行模糊处理
- (UIImage *)blurImage:(CGImageRef)srcImg {
// 创建CIContext,这里关闭color management有助于提升性能
NSDictionary *options = @{ kCIContextWorkingColorSpace : [NSNull null] };
CIContext *mContext = [CIContext contextWithOptions:options];
CIImage *mImg = [[CIImage alloc] initWithCGImage:srcImg];
// 创建高斯模糊滤镜,ios只支持这1种模糊滤镜,并且要ios6.0以上才行,inputRadius最大100,默认10
CIFilter *mBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[mBlurFilter setValue:mImg forKey:kCIInputImageKey];
[mBlurFilter setValue:@(10.0f) forKey:@"inputRadius”];
CIImage *mBlurImg = [mBlurFilter valueForKey:kCIOutputImageKey];
CGImageRef mResultCGImg = [mContext createCGImage:mBlurImg fromRect:[mBlurImg extent]];
UIImage *mResultUIImg = [UIImage imageWithCGImage:mResultCGImg];
CGImageRelease(mDestImg);
[mImg release];
return mResultUIImg;
}
// 对摄像头作模糊处理
// 使用AVFoundation实现摄像头功能并且实现AVCaptureVideoDataOutputSampleBufferDelegate托管协议
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer, 0);
void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
static CGColorSpaceRef colorSpace = nil;
if (colorSpace == nil) {
colorSpace = CGColorSpaceCreateDeviceRGB();
}
CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGImageRef quartzImage = CGBitmapContextCreateImage(context);
// 处理原始图像
UIImage *resultUIImage = [self blurImage:quartzImage];
// 更新某个UIImageView的image(隐藏摄像头的layer,盖一个UIImageView来播放滤镜处理后的图像)
...
CGImageRelease(quartzImage);
CGContextRelease(context);
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
}
参考:
1. Core Image Programming Guide
https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_performance/ci_performance.html#//apple_ref/doc/uid/TP30001185-CH10-SW2
2. Core Image Filter Reference
https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CoreImageFilterReference/Reference/reference.html#//apple_ref/doc/uid/TP40004346
分享到:
相关推荐
iOS滤镜封装,有人脸识别检测,一些有趣的滤镜的封装。
包括了相册的以及很多滤镜的合集,整体还算不错,比起自己写滤镜舒服太多
这个滤镜处理是模仿instagram的图片处理,上面有18种效果,高端模仿,话不多说,自己下载来看吧!
iOS 滤镜属性的小demo做美颜相机需要的小朋友自由下载。
RGB通道滤镜方式 给图片加滤镜 以及GPUImage库,好好研究下 用处很大
前两年IOS应用源码-主要是用于毕业设计学习的。
实现相机滤镜效果,打开相册选择照片,进行滤镜展示,包括 原始" "lomo", "黑白", "怀旧", "哥特", "淡雅", 酒红", "清宁", "浪漫", "光晕", "蓝调", "梦幻", "夜色"等滤镜效果。。
通过滤镜实现一些马赛克,灰白,模糊图片。。等图片的处理 oc代码
一个简单的图片滤镜demo,可以在此基础上加上更多的滤镜效果。注释充分
iOS 拍摄视频时,给视频加上滤镜效果,这是苹果官方的一份demo,值得学习
ios core image 常见滤镜模式
13种滤镜效果
iOS动画系列第六章中文文档 深入学习iOS动画
开源的、非常易用的滤镜类库;包含17种滤镜效果。
基于GPUImage的实时美颜滤镜
一分钟学会给图片添加滤镜效果
GPUImage滤镜效果
iOS 搭建“美图(贴纸,涂鸦,文字,滤镜)”,Image Edit
iOS 滤镜使用,主要用在图片的处理上,比如模糊效果
图片滤镜处理的IOS源码,对摄像头拍摄图像进行实时处理