gpt4 book ai didi

objective-c - iOS 9.3 UIGraphicsImageRenderer 没有显示任何其他选项吗?

转载 作者:行者123 更新时间:2023-12-05 03:09:00 39 4
gpt4 key购买 nike

我想在裁剪时对图像应用羽化效果,但我想使用 UIGraphicsImageRenderer 渲染图像渲染为零(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];

//此处Renderer在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];

最佳答案

UIGraphicsImageRenderer 在 iOS 9 中不可用。如果您需要针对此,您可以轻松地编写自己的代码:

+(instancetype)LT_imageByDrawingOnCanvasOfSize:(CGSize)size usingBlock:(LTImageDrawingContextBlock)block
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(size.width, size.height), NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();

block( context );

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}

关于objective-c - iOS 9.3 UIGraphicsImageRenderer 没有显示任何其他选项吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44082314/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com