以下方法尝试将高斯模糊应用于图像。但是它什么也没做。您能告诉我出什么问题了吗,如果您也知道错了的原因,那也将有所帮助。我正在尝试了解CALayers和quartzcore。
谢谢
-(void)updateFavoriteRecipeImage{
[self.favoriteRecipeImage setImageWithURL:[NSURL URLWithString:self.profileVCModel.favoriteRecipeImageUrl] placeholderImage:[UIImage imageNamed:@"miNoImage"]];
//Set content mode
[self.favoriteRecipeImage setContentMode:UIViewContentModeScaleAspectFill];
self.favoriteRecipeImage.layer.masksToBounds = YES;
//Blur the image
CALayer *blurLayer = [CALayer layer];
CIFilter *blur = [CIFilter filterWithName:@"CIGaussianBlur"];
[blur setDefaults];
blurLayer.backgroundFilters = [NSArray arrayWithObject:blur];
[self.favoriteRecipeImage.layer addSublayer:blurLayer];
[self.favoriteRecipeImage setAlpha:0];
//Show image using fade
[UIView animateWithDuration:.3 animations:^{
//Load alpha
[self.favoriteRecipeImage setAlpha:1];
[self.favoriteRecipeImageMask setFrame:self.favoriteRecipeImage.frame];
}];
}
最佳答案
documentation of the backgroundFilters
property说:
特别注意事项
iOS中的图层不支持此属性。
从iOS 6.1开始,没有用于将实时过滤器应用于iOS上的图层的 public API。您可以编写代码以将基础图层绘制为CGImage
,然后将滤镜应用于该图像并将其设置为图层的背景,但是这样做有点复杂,并且不是“实时的”(如果基础图层无法自动更新图层更改)。
关于ios - 如何使用CALayer模糊图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17223572/