我有一个图像,我正在尝试对其应用堆栈模糊,并想从我创建的 .png 文件中应用蒙版以查看下面的清晰图像。我需要下面的图像才能在给定时间更改,但带有掩码的 blurView 保持静态。这是我正在使用的代码,但我没有得到模糊的蒙版图像。
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *imageview = [UIImageView new];
[imageview setFrame:[self.view bounds]];
[imageview setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[imageview setImage:[UIImage imageNamed:@"myImage.jpg"]];
[imageview setContentMode:UIViewContentModeScaleAspectFill];
[self.view addSubview:imageview];
[self setBlurView:[AMBlurView new]];
[[self blurView] setFrame:CGRectMake(0.f, 0.f, [self.view bounds].size.width, [self.view bounds].size.height)];
[[self blurView] setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self.view addSubview:[self blurView]];
imageview.image = [self maskImage:imageview.image withMask:[UIImage imageNamed:@"mask"]];
}
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
CGImageRef imgRef = [image CGImage];
CGImageRef maskRef = [maskImage CGImage];
CGImageRef actualMask = CGImageMaskCreate(CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef), NULL, false);
CGImageRef masked = CGImageCreateWithMask(imgRef, actualMask);
return [UIImage imageWithCGImage:masked];
}