java毛玻璃_模糊效果(毛玻璃效果)
模糊效果(毛玻璃效果)
效果演示:
1. 使用iOS自帶的 UIImage+ImageEffects 文件
文件中有這么幾個(gè)方法:
- (UIImage *)applyLightEffect;
- (UIImage *)applyExtraLightEffect;
- (UIImage *)applyDarkEffect;
- (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor;
- (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage;
2. 使用 CoreImage 中的模糊濾鏡
coreImage是蘋果用來簡化圖片處理的框架
CIImage, CIFilter與CIContext三者之間的聯(lián)系(CoreImage中三個(gè)重要的類)
示例:
-(UIImage*)applyGaussianBlurImage:(UIImage*)image {
// CIImage
CIImage *ciImage = [[CIImage alloc] initWithImage:image];
// CIFilter(濾鏡的名字, 不要寫錯(cuò) 高斯模糊)
CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
// 將圖片輸入到濾鏡中
[blurFilter setValue:ciImage forKey:kCIInputImageKey];
/**在傳入圖片進(jìn)入濾鏡后,可以更改濾鏡的一些參數(shù)進(jìn)行設(shè)置,比如模糊程度等*/
// NSLog(@"%@", [blurFilter attributes]); // 打印看一下有哪些參數(shù)可以設(shè)置及相關(guān)信息
// inputRadius參數(shù): 模糊的程度 默認(rèn)為10, 范圍為0-100, 接收的參數(shù)為NSNumber類型
// 設(shè)置模糊的程度
[blurFilter setValue:@(8) forKey:@"inputRadius"];
// 將處理好的圖片輸出
CIImage *outImage = [blurFilter valueForKey:kCIOutputImageKey];
// CIContext 上下文(參數(shù)nil->默認(rèn)為CPU渲染, 如果想用GPU渲染來提高效率的話,則需要傳參數(shù))
CIContext *context = [CIContext contextWithOptions:nil];
// 將處理好的圖片創(chuàng)建出來 outImage原來的大小size
CGImageRef outputCGImage = [context createCGImage:outImage
fromRect:[outImage extent]];
UIImage *blurImage = [UIImage imageWithCGImage:outputCGImage];
// 釋放CGImageRef
CGImageRelease(outputCGImage);
return blurImage;
}
3. 使用 UIVisualEffectView (實(shí)時(shí))(iOS8)
//生成該對象
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];//然后添加將其添加到相應(yīng)的UIView 之上
總結(jié)
以上是生活随笔為你收集整理的java毛玻璃_模糊效果(毛玻璃效果)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 卵巢早衰用中药能治好吗
- 下一篇: java程序崩溃怎么重启_android