ios - 如何使用CALayer模糊图像

标签 ios core-animation quartz-core

以下方法尝试将高斯模糊应用于图像。但是它什么也没做。您能告诉我出什么问题了吗,如果您也知道错了的原因,那也将有所帮助。我正在尝试了解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/

相关文章:

ios - 多次调用 CATransaction 完成

iphone - 将 UIWebview 内容转换为 UIImage

ios - Eureka Forms Library 响应一行的文本字段完成编辑?

ios - 显示 MPMediaPickerController 模态后状态栏再次出现

iphone - 如何为 UITableView 标题 View 设置动画

ios - 如何解决 UITableViewCell 中的边框重叠问题?

ios - 是否可以在避免大的性能影响的同时为文本添加发光效果?

objective-c - UIWebView 尖角

ios - 从 Firebase Swift 读取通过 Autoid 存储的数据

iphone - 如何更改 entitlements.plist 的路径