• iOS


    
    
     1 #import <UIKit/UIKit.h>
     2 #import <Accelerate/Accelerate.h>
     3 
     4 @interface UIImage (TY_ImageEditP)
     5 /**
     6  *  对图片进行模糊
     7  *
     8  *  @param image 要处理图片
     9  *  @param blur  模糊系数 (0.0-1.0)
    10  *
    11  *  @return 处理后的图片
    12  */
    13 + (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur;
    14 
    15 @end
    
    
    


    1
    #import "UIImage+TY_ImageEditP.h" 2 3 @implementation UIImage (TY_ImageEditP) 4 + (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur { 5 if (!image) { 6 return nil; 7 } 8 if ((blur < 0.0f) || (blur > 1.0f)) { 9 blur = 0.5f; 10 } 11 12 int boxSize = (int)(blur * 200); 13 boxSize -= (boxSize % 2) + 1; 14 15 CGImageRef img = image.CGImage; 16 17 vImage_Buffer inBuffer, outBuffer; 18 vImage_Error error; 19 void *pixelBuffer; 20 21 CGDataProviderRef inProvider = CGImageGetDataProvider(img); 22 CFDataRef inBitmapData = CGDataProviderCopyData(inProvider); 23 24 inBuffer.width = CGImageGetWidth(img); 25 inBuffer.height = CGImageGetHeight(img); 26 inBuffer.rowBytes = CGImageGetBytesPerRow(img); 27 inBuffer.data = (void*)CFDataGetBytePtr(inBitmapData); 28 29 pixelBuffer = malloc(CGImageGetBytesPerRow(img) * CGImageGetHeight(img)); 30 31 outBuffer.data = pixelBuffer; 32 outBuffer.width = CGImageGetWidth(img); 33 outBuffer.height = CGImageGetHeight(img); 34 outBuffer.rowBytes = CGImageGetBytesPerRow(img); 35 36 error = vImageBoxConvolve_ARGB8888(&inBuffer, &outBuffer, NULL, 37 0, 0, boxSize, boxSize, NULL, 38 kvImageEdgeExtend); 39 40 41 if (error) { 42 NSLog(@"error from convolution %ld", error); 43 } 44 45 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 46 CGContextRef ctx = CGBitmapContextCreate( 47 outBuffer.data, 48 outBuffer.width, 49 outBuffer.height, 50 8, 51 outBuffer.rowBytes, 52 colorSpace, 53 CGImageGetBitmapInfo(image.CGImage)); 54 55 CGImageRef imageRef = CGBitmapContextCreateImage (ctx); 56 UIImage *returnImage = [UIImage imageWithCGImage:imageRef]; 57 58 //clean up 59 CGContextRelease(ctx); 60 CGColorSpaceRelease(colorSpace); 61 62 free(pixelBuffer); 63 CFRelease(inBitmapData); 64 65 CGColorSpaceRelease(colorSpace); 66 CGImageRelease(imageRef); 67 68 return returnImage; 69 } 70 71 @end

    例子~:

    1  __weak typeof(self) weakSelf = self;
    2                 [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) {
    3                     //毛玻璃效果处理
    4                     UIImage *imageN = [UIImage blurryImage:image withBlurLevel:0.2];
    5                     weakSelf.imageN = imageN;
    6                     self.myImageView.image = self.imageN;
    7 
    8                 }];
  • 相关阅读:
    Jsoup解析HTML、加载文档等实例
    MyBatis的学习总结六:Mybatis的缓存【参考】
    MyBatis的学习总结五:调用存储过程【参考】
    MyBatis的学习总结四:实现关联表查询【参考】
    MyBatis的学习总结三:优化MyBatis配置文件中的配置
    Mybatis的学习总结二:使用Mybatis对表进行CRUD操作【参考】
    Mybatis的学习总结:mybatis的入门介绍
    ueditor 编辑器,自定义图片上传
    Java使用HttpURLConnection上传文件(转)
    Maven缺少jar添加方式
  • 原文地址:https://www.cnblogs.com/henusyj-1314/p/9523668.html
Copyright © 2020-2023  润新知