gpt4 book ai didi

objective-c - 用特定颜色填充路径

转载 作者:行者123 更新时间:2023-12-04 05:48:49 26 4
gpt4 key购买 nike

我想用红色填充路径。这是我的代码:

CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f};
CGContextBeginPath(c);
CGContextSetStrokeColor(c, red);
CGContextSetFillColorWithColor(c, [UIColor whiteColor].CGColor);
CGContextMoveToPoint(c, 10, 10);
CGContextAddLineToPoint(c, 20, 20);
CGContextAddLineToPoint(c, 20, 40);
CGContextAddLineToPoint(c, 40, 20);
CGContextAddLineToPoint(c, 10, 10);
CGContextStrokePath(c);
CGContextFillPath(c);

我知道我必须使用 CGContextSetFillColor()CGContextFillPath() ,但它不起作用。

我怎样才能正确地做到这一点?

最佳答案

就我而言,答案是:

CGContextRef context = UIGraphicsGetCurrentContext();

//set fill pattern
UIColor *patternRed = [UIColor colorWithPatternImage:[UIImage imageNamed:@"patternRed.png"]];

CGContextSetLineWidth(context, 1.0);
CGContextSetFillColorWithColor(context, patternRed.CGColor);

CGMutablePathRef pathRef = CGPathCreateMutable();

CGPathMoveToPoint(pathRef, NULL, 0, self.frame.size.height);
for (int i = 0; i<255; ++i) {
CGPathAddLineToPoint(pathRef, NULL, stepX*arrayX[i], self.frame.size.height - (arrayYRed[i]*stepY));
}
CGPathAddLineToPoint(pathRef, NULL, stepX*255, self.frame.size.height);
CGContextAddPath(context, pathRef);
CGContextFillPath(context);

CGPathRelease(pathRef);

关于objective-c - 用特定颜色填充路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10339653/

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