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

  1. 

    

    UIImage *imag = [UIImage imageNamed:@"img"];

     /* --------------------使用 coreImg  ---------------------------  */

 

    // CIImage

    CIImage *ciimg = [[CIImage alloc] initWithImage:imag];   

 

    // CIFilter

    CIFilter *blurFilter =     [CIFilter filterWithName:@"CIGaussianBlur"];

 

    // 可以输出设置的模糊的程度

    NSLog(@"%@",[blurFilter attributes]);

    

    // 根据上一步可以设置模糊程度

    [blurFilter setValue:@(50) forKey:@"inputRadius"];

    

    // 图片输入滤镜

    [blurFilter setValue:ciimg forKey:kCIInputImageKey];

    

    // 将推片输出

    CIImage *outPutImg = [blurFilter valueForKey:kCIOutputImageKey];

    

    // CIContext

    CIContext * context = [CIContext contextWithOptions:nil];

    

    // 获取CGImage句柄

    CGImageRef outImgRef = [context createCGImage:outPutImg fromRect:[outPutImg extent]];

    

    //  h获取到最后的图片

    UIImage *blurImg = [UIImage imageWithCGImage:outImgRef];

    

    // 释放句柄

    CGImageRelease(outImgRef);

    

    // 最后得到模糊的图片    blurImg

 

 

    第二种

    /* ___________________ UIImage+ImageEffects.h ________________________________ */

    UIImage *sourImg = [UIImage imageNamed:@"img"];

    

    UIImage *blurImg = [sourImg blurImageWithRadius:30];

 

 

第三种                    UIVisualEffectView

 

 

 

   UIScrollView *sc = [[UIScrollView alloc] initWithFrame:self.view.bounds];

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 600, 500)];

    imgView.image = imag;

    [sc addSubview:imgView];

    sc.contentSize = imgView.bounds.size;

    [self.view addSubview:sc];

 

    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];

    

    effectView.frame = CGRectMake(0, 200, 400, 200);

    [self.view addSubview:effectView];

    

    

    

    UILabel *lable = [[UILabel alloc] initWithFrame:effectView.bounds];

    lable.text = @"模糊背景";

    lable.font = [UIFont systemFontOfSize:50];

    lable.textAlignment = NSTextAlignmentCenter;

    

    //  添加模糊的子effictView  使用的是  --  UIVibrancyEffect  且需要和父类保持一致

    UIVisualEffectView *subEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIVibrancyEffect effectForBlurEffect:(UIBlurEffect *)effectView.effect]];

    

    subEffectView.frame = effectView.bounds;

    // 将子模糊View 添加到EffectView contenctView 才能有效果

    

    [effectView.contentView addSubview:subEffectView];

    

    [subEffectView.contentView addSubview:lable];

 

    

转载于:https://www.cnblogs.com/paocai2015/p/5410466.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值