#import <UIKit/UIKit.h>
#import <Accelerate/Accelerate.h>
#import <QuartzCore/QuartzCore.h> @interface UIImage (Blur) // 0.0 to 1.0
- (UIImage*)blurredImage:(CGFloat)blurAmount; @end #import "UIImage+Blur.h" @implementation UIImage (Blur) - (UIImage*)blurredImage:(CGFloat)blurAmount
{
if (blurAmount < 0.0 || blurAmount > 1.0) {
blurAmount = 0.5;
} int boxSize = (int)(blurAmount * );
boxSize = boxSize - (boxSize % ) + ; CGImageRef img = self.CGImage; vImage_Buffer inBuffer, outBuffer;
vImage_Error error; void *pixelBuffer; CGDataProviderRef inProvider = CGImageGetDataProvider(img);
CFDataRef inBitmapData = CGDataProviderCopyData(inProvider); inBuffer.width = CGImageGetWidth(img);
inBuffer.height = CGImageGetHeight(img);
inBuffer.rowBytes = CGImageGetBytesPerRow(img); inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData); pixelBuffer = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img)); outBuffer.data = pixelBuffer;
outBuffer.width = CGImageGetWidth(img);
outBuffer.height = CGImageGetHeight(img);
outBuffer.rowBytes = CGImageGetBytesPerRow(img); error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL, , , boxSize, boxSize, NULL, kvImageEdgeExtend); if (!error) {
error = vImageBoxConvolve_ARGB8888(&outBuffer, &inBuffer, NULL, , , boxSize, boxSize, NULL, kvImageEdgeExtend); if (!error) {
error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL, , , boxSize, boxSize, NULL, kvImageEdgeExtend);
}
} CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef ctx = CGBitmapContextCreate(outBuffer.data,
outBuffer.width,
outBuffer.height,
,
outBuffer.rowBytes,
colorSpace,
(CGBitmapInfo)kCGImageAlphaNoneSkipLast); CGImageRef imageRef = CGBitmapContextCreateImage (ctx); UIImage *returnImage = [UIImage imageWithCGImage:imageRef]; CGContextRelease(ctx);
CGColorSpaceRelease(colorSpace); free(pixelBuffer);
CFRelease(inBitmapData); CGColorSpaceRelease(colorSpace);
CGImageRelease(imageRef); return returnImage;
} @end // 使用

UIImage *image = [[UIImage imageNamed:@"xxxx.png"] blurredImage:0.6];

 

IOS UIImage 模糊的更多相关文章

  1. iOS UIImage DownLoad图片的下载缓存全部在此

    iOS图片的下载缓存全部在此 分类: iOS编程 -- : 2075人阅读 评论() 收藏 举报 注意: 我的文章只写给自己看 ------------------------------------ ...

  2. IOS 图片模糊处理 ------ 直接代码 复制出去就可用 值得标记

    1. UIImage *imag = [UIImage imageNamed:@"img"]; /* --------------------使用 coreImg  ------- ...

  3. iOS UIImage:获取图片主色调

    本文转载至 http://www.wahenzan.com/a/mdev/ios/2015/0325/1677.html -(UIColor*)mostColor{ #if __IPHONE_OS_V ...

  4. iOS 8 模糊视图(毛玻璃效果)的简单实现UIVisualEffectView

    在须要模糊的UIView上.加入一个UIVisualEffectView对象就可以. 效果例如以下图: 代码例如以下: UIImageView *imageview = [[UIImageViewal ...

  5. [iOS] UIImage和CGImageRef

    CGImageRef并不是面向对象的API,也不是类,只是一个指针类型,Quartz 2D对CGImageRef的定义为: typedef struct CGImage *CGImageRef; 由此 ...

  6. iOS UIimage初始化时的两种方法

    第一种方式:UIImage *image = [UIImage imageNamed:@"image"]; 使用这种方式,第一次读取的时候,先把这个图片存到缓存里,下次再使用时直接 ...

  7. iOS UIImage扩展方法(category):放大、旋转、合并UIImage、增加渐变层、添加阴影、调节透明度、保存到相册

    一有用的 UIImage 扩展,支持(等比例)放大和旋转可在许多 App 中使用. UIImage-Extensions.h #import <Foundation/Foundation.h&g ...

  8. IOS FMDB模糊查询

    http://blog.sina.com.cn/s/blog_9630f1310101fx1d.html /查询记录 -(NSArray*)selectitemDream_desc:(JiemengS ...

  9. <iOS>UIImage变为NSData并进行压缩

    http://www.cnblogs.com/robinkey/archive/2013/01/21/2869930.html //sdk中提供了方法可以直接调用 UIImage *img = [UI ...

随机推荐

  1. STM32F051 IAP源代码分享

    STM32F051 IAP源代码分享 假设不懂IAP的请自己主动脑补或者怒戳这里 http://www.openedv.com/posts/list/11494.htm 然后STM32F051的IAP ...

  2. [Regular Expressions] Find Repeated Patterns

    Regular Expression Quantifiers allow us to identify a repeating sequence of characters of minimum an ...

  3. String源码学习

    String源码学习 零散的收获 数组的元素类型可以通过getComponentType来获取到 子类型的数组可以赋值给父类型的数组,.但是并不存在继承关系.数组的父类是Object. 通过声明如下代 ...

  4. C#遍历Object各个属性含List泛型嵌套。

    同事遇到一个问题:在做手机app接口时,返回JSON格式,json里面的数据属性均是string类型,但不能出现NULL(手机端那边说处理很麻烦,哎).Model已经创建好了,而且model的每个属性 ...

  5. SQL获取选中时间的交集

    如上图:t1,t2代表要选择的时间段,t3,t4代表系统时间. 那么如果要获取选中时间段所有的交集为: 条件1 and ((t3>t1 and t1>t2) or (t3<t2 an ...

  6. ios学习资料(一)

    IT社区: http://www.cnblogs.com/ http://www.csdn.net/ http://www.51cto.com/ http://www.cocoachina.com/ ...

  7. call()与apply()传参需要注意的一点

    call()与apply()是用来改变函数体内的this指向,第一个参数是调用函数的母对象,他是调用上下文,函数体内通过this来获得对它的引用,换句话说就是第一参数===函数中的this. 但是如下 ...

  8. C# 窗体程序入门 之计算器

    之前一直在java的B/S,这次被要求做一个C/S,其中客户端主要是界面和socket通信.因为没有使用过C#和Visual Studio的控件编程,先来个HelloWorld. 我的环境是visua ...

  9. 关于Eclipse中Jsp页面打不开并且显示Failed to create the part's controls的解决办法

    问题描述:同事从svn上导入的一个项目,jdk都设置好了以后,java.xml.html等文件都能打开,唯独jsp文件打不开,并且显示Failed to create the part's contr ...

  10. C++中的cout输出机制

    代码: #include <iostream> using namespace std; int hello(){ cout<<"hello"<< ...