#import <UIKit/UIKit.h>
#import <Accelerate/Accelerate.h> @interface UIImage (TY_ImageEditP)
/**
* 对图片进行模糊
*
* @param image 要处理图片
* @param blur 模糊系数 (0.0-1.0)
*
* @return 处理后的图片
*/
+ (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur; @end


 1 #import "UIImage+TY_ImageEditP.h"

 @implementation UIImage (TY_ImageEditP)
+ (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur {
if (!image) {
return nil;
}
if ((blur < 0.0f) || (blur > 1.0f)) {
blur = 0.5f;
} int boxSize = (int)(blur * );
boxSize -= (boxSize % ) + ; CGImageRef img = image.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) {
NSLog(@"error from convolution %ld", error);
} CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(
outBuffer.data,
outBuffer.width,
outBuffer.height,
,
outBuffer.rowBytes,
colorSpace,
CGImageGetBitmapInfo(image.CGImage)); CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
UIImage *returnImage = [UIImage imageWithCGImage:imageRef]; //clean up
CGContextRelease(ctx);
CGColorSpaceRelease(colorSpace); free(pixelBuffer);
CFRelease(inBitmapData); CGColorSpaceRelease(colorSpace);
CGImageRelease(imageRef); return returnImage;
} @end

例子~:

  __weak typeof(self) weakSelf = self;
[self.myImageView sd_setImageWithURL:[NSURL URLWithString:[ZLModel checkImageUrlNsstring:myModel.address withHttp:TY_IMAGEURL]] placeholderImage:[UIImage imageNamed:consultDefault] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//毛玻璃效果处理
UIImage *imageN = [UIImage blurryImage:image withBlurLevel:0.2];
weakSelf.imageN = imageN;
self.myImageView.image = self.imageN; }];

iOS - 毛玻璃效果封装的更多相关文章

  1. iOS 毛玻璃效果的实现方法

    iOS开发中有的时候需要将图片设置模糊,来实现特定的效果获取更好的用户体验, iOS7之后半透明模糊效果得到大范围使用的比较大,现在也可以看到很多应用局部用到了图片模糊效果,可以通过高斯模糊和毛玻璃效 ...

  2. iOS毛玻璃效果的实现方法

    ios开发中常常用到的毛玻璃效果实现方法 iOS8以后使用系统里的UIBlurEffect可以实现,UIBlurEffect继承自UIVisualEffect UIBlurEffectStyle有三个 ...

  3. ios毛玻璃效果

    方法一:支持所有ios系统版本: - (void)setupBlurView { UIImageView *darkView = [[UIImageView alloc] init]; darkVie ...

  4. ios 毛玻璃效果

    推荐第三方库: https://github.com/nicklockwood/FXBlurView FXBlurView*Fx=[[FXBlurView alloc]initWithFrame:CG ...

  5. iOS 实现毛玻璃效果

    话说苹果在iOS7.0之后,很多系统界面都使用了毛玻璃效果,增加了界面的美观性,比如下图的通知中心界面; 但是其iOS7.0的SDK并没有提供给开发者实现毛玻璃效果的API,所以很多人都是通过一些别人 ...

  6. iOS模糊效果(毛玻璃效果)的实现

    前一段时间项目中用到毛玻璃效果,那时对UIBlurEffect类和 UIVisualEffectView这两个类做了一部分了解.但当时并没有去特别的深入研究,直到项目做完后,才静下心来好好研究了一番. ...

  7. iOS开发探索-高斯模糊&毛玻璃效果

    iOS开发中有的时候需要将图片设置模糊,来实现特定的效果获取更好的用户体验, iOS7之后半透明模糊效果得到大范围使用的比较大,现在也可以看到很多应用局部用到了图片模糊效果,可以通过高斯模糊和毛玻璃效 ...

  8. iOS开发小技巧--实现毛玻璃效果的方法

    一.美工出图 二.第三方框架 -- DRNRealTimeBlur,框架继承自UIView.使用方法:创建UIView直接继承自框架的View,就有了毛玻璃效果 三.CoreImage -- 图片加高 ...

  9. iOS毛玻璃擦除效果

    思路:首先我的思路放两个imageView在Controller里把高清的图片放在下面,带有毛玻璃效果的图片放在上面. //在Controller的view上加一个手势代码如下(温馨提示,开启imae ...

随机推荐

  1. {"errmsg":"invalid weapp pagepath hint: [IunP8a07243949]","errcode":40165}微信的坑

    使用微信官方文档,发送请求会报错--   pagepath无效! 正确修改-- 将标红的pagepath改成 page与上面相同即可

  2. Java如何将十六进制数转换为十进制数的自编程序

    package com.swift;//所属包 import java.util.Scanner;//导入扫描器 public class Hex2Decimal { public static vo ...

  3. 问题008:java 中代码块的风格有几种?单行注释可否嵌套?多行注释可否嵌套?

    有两种:一种是次行风格,英文称为next-line 一种是是行尾风格,英文称为 end-of-line 举例 行尾风格 public class HelloWorld{ public static v ...

  4. mysql 复制一列到另一列

    https://www.cnblogs.com/clphp/p/6251469.html

  5. node操作mogondb数据库的封装

    注:摘自网络 上面的注释都挺详细的,我使用到了nodejs的插件mongoose,用mongoose操作mongodb其实蛮方便的. 关于mongoose的安装就是 npm install -g mo ...

  6. MySQL 时间戳与日期互相转换

    MySQL 时间戳与日期互相转换 1.时间戳转换成日期 函数:FROM_UNIXTIME() ,'%Y年%m月%d日') 结果为:2015年04月15日 2.把日期转换为时间戳,和 FROM_UNIX ...

  7. rpc - 接口返回数据结构的设计

    方案一: 系统级状态  .业务级别的状态同用 code要特殊声明保留状态,如若不声明保留状态,一旦业务开发人员用到了系统级的状态,就有必要侵入的改动业务返回的code(新code与业务欲返回的code ...

  8. JZOJ 3223. 【HBOI2013】Ede的新背包问题

    3223. [HBOI2013]Ede的新背包问题 (Standard IO) Time Limits: 2000 ms  Memory Limits: 262144 KB  Detailed Lim ...

  9. 自动化运维之使用Python3收发电子邮件~~~附源码

    一.背景介绍   1.1  一些专业名称的解释 MUA——Mail User Agent,邮件用户代理.是用户与电子邮件系统的交互接口,一般来说它就是我们PC机上的一个程序,提供一个好的用户界面,它提 ...

  10. 遗传算法 | C++版GA_TSP

    嗯哼,时隔半年,再次有时间整理关于组合优化问题——旅行商问题(Traveling Salesman Problem, TSP),这次采用的是经典遗传算法(Genetic Algorithm, GA)进 ...