[IOS 开发代码]UIImage+Blur 网络图片模糊用法
UIImage-Helpers 网络图片模糊用法
float quality = .00001f;
float blurred = .5f; NSURL *url = [NSURL URLWithString:@"http://pic21.nipic.com/20120614/10230657_130343324168_2.jpg"];
NSData *data = [[NSData alloc]initWithContentsOfURL:url];
UIImage *img = [[UIImage alloc]initWithData:data]; NSData *imageData = UIImageJPEGRepresentation(img, quality);
userIcon.image = [[UIImage imageWithData:imageData] blurredImage:blurred];
//
// UIImage+Blur.h #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
//
// UIImage+Blur.m #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) {
#ifdef DEBUG
NSLog(@"%s error: %zd", __PRETTY_FUNCTION__, error);
#endif return self;
} 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); CGImageRelease(imageRef); return returnImage;
} @end
[IOS 开发代码]UIImage+Blur 网络图片模糊用法的更多相关文章
- iOS开发中关于UIImage的知识点总结
UIImage是iOS中层级比较高的一个用来加载和绘制图像的一个类,更底层的类还有 CGImage,以及iOS5.0以后新增加的CIImage.今天我们主要聊一聊UIImage的三个属性: image ...
- 李洪强iOS开发之 - enum与typedef enum的用法
李洪强iOS开发之 - enum与typedef enum的用法 01 - 定义枚举类型 上面我们就在ViewController.h定义了一个枚举类型,枚举类型的值默认是连续的自然数,例如例子中的T ...
- IOS开发之异步加载网络图片并缓存本地实现瀑布流(二)
/* * @brief 图片加载通用函数 * @parma imageName 图片名 */ - (void)imageStartLoading:(NSString *)imageName{ NSUR ...
- iOS开发多线程篇 08 —GCD的常见用法
iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...
- 基于OpenCV的人脸识别[iOS开发笔记(2)]
开始了OpenCV的试水工作了... 1.Get ready 在OpenCV中我们会使用函数cv::CascadeClassifier 来进行人脸检测.但是在使用本函数之前我们需要添加一个XML文件对 ...
- [iOS开发]WKWebView加载JS
最近项目要用webView加载js文件,挺同事说WKWebView比UIWebView更加好用,于是我今天就试试,百度一发,自己写了个demo. 先看我写的代码,然后再来看WKWebView跟UIWe ...
- [IOS 开发]TableView如何刷新指定的cell 或section
//一个section刷新 NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:]; [tableview reloadSections:ind ...
- IOS开发笔记 - 基于SDWebImage的网络图片加载处理
前言: 在IOS下通过URL读一张网络图片并不像Asp.net那样可以直接把图片路径放到图片路径的位置就ok, 而是需要我们通过一段类似流的方式去加载网络图片,接着才能把图片放入图片路径显示. 这里找 ...
- IOS开发-代码规范
代码风格的重要性对于一个团队和项目来说不言而喻.网上有许多 Objective-C 的代码风格,但这份简洁而又最符合苹果的规范,同时有助于养成良好的代码习惯,也是我们团队一直遵循的代码风格. 写法没有 ...
随机推荐
- JavaScript---function、this关键字相关习题
1. 请看下列代码: function F( ){ function C( ){ return this; } return C(); } var o=new F( ); 请问上面的this值指向的是 ...
- webpack react基础配置二 热加载
用到 webpack-dev-server 先安装,注意 装到全局 还是本项目我也没注意 因为之前一直报错,有很小可能是安装到本地解决了,或者是我网络问题: 装到全局:$ npm install ...
- SpringMVC框架下实现JSON(类方法中回传数据到jsp页面,使用jQuery方法回传)
JSON的实现,即将需要的数据回传到jsp页面: 1>.加入实现Json的三个架包到lib中:2>.目标方法上边加入注解,需要返回的值3>.在jsp页面中书写jQuery方法: ec ...
- Java当中的反射
1:反射的概念 反射是指一类应用,它们能够自描述和自控制.也就是说,这类应用通过采用某种机制来实现对自己行为的描述(self-representation)和监测(examination),并能根据自 ...
- SharePoint常用目录介绍
SharePoint常用目录介绍 stsadm命令管理程序目录:C:\Program Files\Common Files\Microsoft Shared\web server extensions ...
- 21-React的学习
# React的学习 React概述: React是一个用于构建用户界面的JavaScript库. React主要用于构建UI,很多人认为React是MVC中的V(视图). React起源于Faceb ...
- Activty四种启动模式
Activty启动提供了四种启动模式.launchMode: standard:每次启动新的活动窗口(new操作) singleTop:如果在栈顶是目标活动,则直接打开.否则开启新的活动窗口(new) ...
- ognl.OgnlException: target is null for setProperty(null, "emailTypeNo", [Ljava.lang.String;@1513fd0)
[com.opensymphony.xwork2.ognl.OgnlValueStack] - Error setting expression 'emaiTypeDto.emailTypeNo' w ...
- php set_time_limit()用法测试详解
在php中set_time_limit函数是用来限制页面执行时间的,如我想把一个php页面的执行时间定义为5秒就可以set_time_limit(5)了. 一个php脚本通过crontab每5分钟 ...
- Mac上配置Privoxy
此文档适用于走Shadowsocks代理,想利用Privoxy将主机作为代理服务器的用户. 0.安装完Privoxy后,打开终端命令. 1.打开Privoxy的配置文件config: cd /usr/ ...