如何使用CALayer模糊图像

Wil*_*con 1 core-animation ios 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];
    }];
}
Run Code Online (Sandbox Code Playgroud)

rob*_*off 5

物业文件backgroundFilters说:

特别注意事项

iOS中的图层不支持此属性.

从iOS 6.1开始,没有用于将实时过滤器应用于iOS上的图层的公共API.您可以编写代码以将底层图层绘制到a CGImage,然后将滤镜应用于该图像并将其设置为图层的背景,但这样做有点复杂并且不是"实时"(如果底层图层不会自动更新)更改).