/******? ? 模糊? ? *******/
// 加載一張圖片
UIImage *image = [PlusAnimate createImageWithColor:[UIColor blackColor]];
// 1.創(chuàng)建CIImage
CIImage *ciImage = [[CIImage alloc] initWithImage:image];
// 2.創(chuàng)建濾鏡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參數(shù)為nil代表用CPU渲染,若想用GPU渲染請查看此參數(shù))
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;
}