本文主要是介绍[IOS 开发] 为UIImage 绘制 毛玻璃效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
为uiimage 绘制 毛玻璃效果
//给Image增加
- (UIImage *)applyBlurRadius:(CGFloat)radius toImage:(UIImage *)image
{if (radius < 0){radius = 0;}CIContext *context = [CIContext contextWithOptions:nil];CIImage *inputImage = [CIImage imageWithCGImage:image.CGImage];// Setting up gaussian blurCIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];[filter setValue:inputImage forKey:kCIInputImageKey]; [filter setValue:[NSNumber numberWithFloat:radius] forKey:@"inputRadius"];CIImage *result = [filter valueForKey:kCIOutputImageKey];CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];UIImage *returnImage = [UIImage imageWithCGImage:cgImage];CGImageRelease(cgImage);return returnImage;
}//把view转换成Image
-(UIImage *)convertViewToImage
{UIGraphicsBeginImageContext(self.bounds.size);[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];UIImage *image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return image;
}
这篇关于[IOS 开发] 为UIImage 绘制 毛玻璃效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!