[英]Blur UIImageView with gradient alpha
How would I make an UIImageView
have a gradient blurred background
? 如何使UIImageView
具有渐变模糊的background
? In other words, the image is fully blurred
on the left and it gets less blurred on the right? 换句话说,图像在左侧完全blurred
,而在右侧则较少模糊?
we did the same in a proyect! 我们在一个proyect中做了同样的事情! we used this method: 我们使用了这种方法:
(UIImage *)blurImage:(CGImageRef*)image withBlurLevel:(CGFloat)blur
{
CIImage *inputImage = [CIImage imageWithCGImage:image];
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"
keysAndValues:kCIInputImageKey, inputImage, @"inputRadius", @(blur), nil];
CIImage *outputImage = filter.outputImage;
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef outImage = [context createCGImage:outputImage
fromRect:[inputImage extent]];
UIImage *returnImage = [UIImage imageWithCGImage:outImage];
CGImageRelease(outImage);
return returnImage;
}
This code use your GPU to make the blur, but you need to call that method in another thread if you don't want your UI to be blocked for a second. 这段代码使用GPU进行模糊处理,但是如果您不希望UI阻塞一秒钟,则需要在另一个线程中调用该方法。
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.