我想在裁剪时对图像应用羽毛效果,但希望我使用 UIGraphicsImageRenderer 渲染图像,渲染为 nil(iOS 9.3)是否还有其他选项可以在 iOS 9.3 中渲染图像
这是我的代码:
UIImage* Img = _myimage;
UIImageView * imageview = [[UIImageView alloc]initWithImage:Img];
[imageview setFrame:CGRectMake(0, 0, Img.size.width, Img.size.height)];
UIBezierPath *aPath;
CAShapeLayer *shapeLayer;
aPath = [UIBezierPath bezierPath];
aPath.contractionFactor = 0.8;
NSValue *mvalue = [_pointsarray objectAtIndex:0];
CGPoint mp2 = [mvalue CGPointValue];
[aPath moveToPoint:mp2];
[aPath addBezierThroughPoints:_pointsarray];
[aPath closePath];
aPath.lineWidth = 2;
shapeLayer = [CAShapeLayer new];
shapeLayer.path=aPath.CGPath;
[shapeLayer setFillColor:[UIColor redColor].CGColor];
[shapeLayer fillColor];
//这里的渲染器在 iOS 9.3 中是 nil
UIGraphicsImageRenderer * renderer = [[UIGraphicsImageRenderer alloc] initWithSize:Img.size];
UIImage *shapeImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context)
{
[shapeLayer renderInContext: context.CGContext];
}];
CIImage * shapeCimage = [[CIImage alloc] initWithImage:shapeImage];
CIFilter * gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlurFilter setValue:shapeCimage forKey: @"inputImage"];
[gaussianBlurFilter setValue:@8 forKey:@"inputRadius"];
CIImage * blurredCIImage = [gaussianBlurFilter valueForKey:kCIOutputImageKey];
UIImage * blurredImage = [UIImage imageWithCIImage:blurredCIImage];
UIImageView *maskedImageView = [[UIImageView alloc]initWithImage:blurredImage];
maskedImageView.contentMode = UIViewContentModeScaleAspectFit;
maskedImageView.frame = imageview.frame;
imageview.layer.mask=maskedImageView.layer;
[self.view addSubview:imageview];