color转image在模糊

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

// 加载一张图片

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在模糊)