gpt4 book ai didi

iphone - Core Graphics 画线带轮廓

转载 作者:行者123 更新时间:2023-12-01 22:43:00 24 4
gpt4 key购买 nike

我正在使用 Core Graphics 绘制一条宽度为 4 像素的任意线,现在我希望这条线具有另一种颜色的 1 像素轮廓。我看不到任何可以“开箱即用”的 CG 功能,但我正在寻找有关如何完成的建议。这是我现有的代码:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 4.0);

CGPoint curPoint = [(NSValue*)[points objectAtIndex:0] CGPointValue];
CGContextMoveToPoint(context, curPoint.x, curPoint.y);

for( int i = 1; i < [points count]; i++ ) {
curPoint = [(NSValue*)[points objectAtIndex:i] CGPointValue];
CGContextAddLineToPoint(context, curPoint.x, curPoint.y);
CGContextStrokePath(context);
CGContextMoveToPoint(context, curPoint.x, curPoint.y);
}

这会产生单行。我想生成一条 4px 线,一条 1px 线突出显示 4px 线,如下所示:

最佳答案

iOS 5.0 添加了一项新功能 CGPathCreateCopyByStrokingPath() 可以满足您的需求。

首先为黑色路径创建一个CGPathRef,然后使用CGPathCreateCopyByStrokingPath()创建一个副本。

这将为您提供一条新路径,您可以用黑色填充并用红色描边,以获得您想要的内容。

此外,创建路径有点慢。您应该避免在执行屏幕绘制时创建路径。您的所有路径都应存储在 RAM 中,并在您开始绘制到屏幕上之前准备就绪。 drawRect: 应该只绘制路径,而不是创建路径。

关于iphone - Core Graphics 画线带轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8960249/

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