zoukankan      html  css  js  c++  java
  • 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];

     

        

  • 相关阅读:
    Oracle11g 干净卸载
    linux中的帮助命令
    Linux Samba文件共享服务,安装与案例配置
    linux文件系统相关命令(df/du/fsck/dumpe2fs)
    虚拟机VMware下CentOS6.6安装教程图文详解
    vnc连接远端linux服务器
    mysql57重新安装后无法再次启动mysql57服务“本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动。”--解决方法
    (二)分布式数据库tidb-事务
    Centos 6下使用cmake编译安装MariaDB
    MySQL数据库基本知识
  • 原文地址:https://www.cnblogs.com/paocai2015/p/5410466.html
Copyright © 2011-2022 走看看