gpt4 book ai didi

ios - CoreGraphics-两个四边形形状的路径之间可见的间隙

转载 作者:行者123 更新时间:2023-12-01 20:04:55 26 4
gpt4 key购买 nike

我已经使用CoreGraphics绘制了两个四边形(4面)形状的路径。总共有6个点,path1使用前4个点,path2使用后4个点,因此都共享2个点。

代码如下

- (void)drawRect:(CGRect)rect {

CGPoint topLeft = CGPointMake(121, 116);
CGPoint topRight = CGPointMake(221, 216);

CGPoint middleLeft = CGPointMake(121, 180);
CGPoint middleRight = CGPointMake(221, 280);

CGPoint bottomLeft = CGPointMake(121, 244);
CGPoint bottomRight = CGPointMake(221, 344);

CGMutablePathRef subpath1 = CGPathCreateMutable();
CGPathMoveToPoint(subpath1, NULL, topLeft.x, topLeft.y);
CGPathAddLineToPoint(subpath1, NULL, topRight.x, topRight.y);
CGPathAddLineToPoint(subpath1, NULL, middleRight.x, middleRight.y);
CGPathAddLineToPoint(subpath1, NULL, middleLeft.x, middleLeft.y);
CGPathAddLineToPoint(subpath1, NULL, topLeft.x, topLeft.y);

CGMutablePathRef subpath2 = CGPathCreateMutable();
CGPathMoveToPoint(subpath2, NULL, middleLeft.x, middleLeft.y);
CGPathAddLineToPoint(subpath2, NULL, middleRight.x, middleRight.y);
CGPathAddLineToPoint(subpath2, NULL, bottomRight.x, bottomRight.y);
CGPathAddLineToPoint(subpath2, NULL, bottomLeft.x, bottomLeft.y);
CGPathAddLineToPoint(subpath2, NULL, middleLeft.x, middleLeft.y);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.19 green:0.42 blue:0.09 alpha:1.0].CGColor);
CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextSetAlpha(context, 1.0);

CGContextAddPath(context, subpath1);
CGContextFillPath(context);

CGContextAddPath(context, subpath2);
CGContextFillPath(context);
}

输出图像是

enter image description here

但是在屏幕上,连接边缘出现了一条奇怪的白线。我要删除白线。

任何人都可以帮助避免这种白线吗?

最佳答案

首先将两个路径都添加到上下文中,然后填充它。

- (void)drawRect:(CGRect)rect {

CGPoint topLeft = CGPointMake(121, 116);
CGPoint topRight = CGPointMake(221, 216);

CGPoint middleLeft = CGPointMake(121, 180);
CGPoint middleRight = CGPointMake(221, 280);

CGPoint bottomLeft = CGPointMake(121, 244);
CGPoint bottomRight = CGPointMake(221, 344);

CGMutablePathRef subpath1 = CGPathCreateMutable();
CGPathMoveToPoint(subpath1, NULL, topLeft.x, topLeft.y);
CGPathAddLineToPoint(subpath1, NULL, topRight.x, topRight.y);
CGPathAddLineToPoint(subpath1, NULL, middleRight.x, middleRight.y);
CGPathAddLineToPoint(subpath1, NULL, middleLeft.x, middleLeft.y);
CGPathAddLineToPoint(subpath1, NULL, topLeft.x, topLeft.y);

CGMutablePathRef subpath2 = CGPathCreateMutable();
CGPathMoveToPoint(subpath2, NULL, middleLeft.x, middleLeft.y);
CGPathAddLineToPoint(subpath2, NULL, middleRight.x, middleRight.y);
CGPathAddLineToPoint(subpath2, NULL, bottomRight.x, bottomRight.y);
CGPathAddLineToPoint(subpath2, NULL, bottomLeft.x, bottomLeft.y);
CGPathAddLineToPoint(subpath2, NULL, middleLeft.x, middleLeft.y);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [UIColor colorWithRed:0.19 green:0.42 blue:0.09 alpha:1.0].CGColor);
CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextSetAlpha(context, 1.0);

// Changes start here...
CGContextAddPath(context, subpath1);
CGContextAddPath(context, subpath2);
CGContextFillPath(context);
}

关于ios - CoreGraphics-两个四边形形状的路径之间可见的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39206257/

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