美文网首页
color转image在模糊

color转image在模糊

作者: 楠Y | 来源:发表于2017-03-16 10:20 被阅读11次

/******    模糊    *******/

// 加载一张图片

UIImage *image = [PlusAnimate createImageWithColor:[UIColor blackColor]];

// 1.创建CIImage

CIImage *ciImage = [[CIImage alloc] initWithImage:image];

// 2.创建滤镜CIFilter

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

// 2.1.将CIImage输入到滤镜中

[blurFilter setValue:ciImage forKey:kCIInputImageKey];

// 可以通过该方法查看我们可以设置的值(如模糊度等)

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

// 2.2设置模糊度

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

// 2.3将处理好的图片输出

CIImage *outCiImage = [blurFilter valueForKey:kCIOutputImageKey];

// 3.CIContext(option参数为nil代表用CPU渲染,若想用GPU渲染请查看此参数)

CIContext *context = [CIContext contextWithOptions:nil];

// 4.获取CGImage句柄

CGImageRef outCGImage = [context createCGImage:outCiImage fromRect:[outCiImage extent]];

// 5.获取最终的图片

UIImage *blurImage = [UIImage imageWithCGImage:outCGImage];

// 6.释放CGImage

CGImageRelease(outCGImage);

/*****************************************/

UIImageView *imageV = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];

imageV.image = blurImage;

imageV.center = self.center;

[self addSubview:imageV];

}

+ (UIImage*)createImageWithColor:(UIColor*) color

{

CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);

CGContextFillRect(context, rect);

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return theImage;

}

相关文章

  • color转image在模糊

    /****** 模糊 *******/ // 加载一张图片 UIImage *image = [PlusA...

  • 背景

    background-color: background-image:[,

  • iOS swift-color转image

    //传递颜色,size返回image func imageFromColor(color: UIColor, vi...

  • Decoration

    abstract class 1. BoxDecoration color: Color image: Decor...

  • color转换image

    该方法主要用于将 UIColor 转化为 UIImage ,用于项目中,放在代码块中,方便使用

  • Golang标准库——image

    image image实现了基本的2D图片库。基本接口叫作Image。图片的色彩定义在image/color包。I...

  • CSS基础

    background属性 color image repeat attachment position ...

  • Independent color

    This is a free image color matching software, for providi...

  • [Pillow]-Reference-Image Module-

    Image.new(mode, size, color=0) Image.new(mode, size, colo...

  • NSData

    // let image = UIImage.imageViewColor(color: UICol...

网友评论

      本文标题:color转image在模糊

      本文链接:https://www.haomeiwen.com/subject/mludnttx.html