gpt4 book ai didi

objective-c - NSBezierPath 三次贝塞尔曲线To 看起来像一条直线

转载 作者:行者123 更新时间:2023-12-03 16:44:32 25 4
gpt4 key购买 nike

我正在创建一个应用程序,它读取 SVG 文件,解析它们,并使用 NSBezierPath 在 Cocoa 中重新绘制它们。矢量路径如下:

M0 126C0.0507812 106.402 0.443359 78.6089 24.0781 76.0034 29.9937 75.3516 34.063 75.6162 39.6509 74 50.0083 71.0044 48.9268 69.8765 54.7329 60.0034 64.9927 42.5586 75.5684 42.8237 94.0801 42.0195 120.367 40.8779 127.438 2.28662 155.885 2.85254 156.091 1.86523 155.896 0.98877 156 0

在 Illustrator 中看起来非常完美;它是一个短的、波浪形的部分。在我的应用程序中,位置是正确的,但曲线显示为直线(见下图)。

Illustrator My application

我可能会错过什么?下面是我的绘图例程,它从一个数组中获取,该数组保存了保存在不同矢量模型中的所有值。

- (void)processImage
{
float factorX = 1;
float factorY = 1;

debugLog(@"[sharedValues paths] is %lu long.", [[sharedValues paths]count]);

NSArray *objectArray = [sharedValues paths];
[[NSColor blackColor] set];
aPath = [NSBezierPath bezierPath];
[aPath moveToPoint:NSMakePoint(0.0, 0.0)];

for(int i=0; i<[objectArray count]; i++) {
debugLog(@"I am in iteration %i", i);
if([[[objectArray objectAtIndex:i] type]isEqualToString:@"AbsoluteMoveTo"]){
AbsoluteMoveToModel *model = [objectArray objectAtIndex:i];
[aPath moveToPoint:NSMakePoint([model x] * factorX, [model y] * factorY)];
} else if([[[objectArray objectAtIndex:i] type]isEqualToString:@"RelativeMoveTo"]){
debugLog(@"Drawing a relative path moveto");
RelativeMoveToModel *model = [objectArray objectAtIndex:i];
[aPath relativeMoveToPoint:NSMakePoint([model x] * factorX, [model y] * factorY)];
} else if([[[objectArray objectAtIndex:i] type]isEqualToString:@"AbsoluteLineTo"]){
debugLog(@"Drawing an absolute path lineto");
AbsoluteLineToModel *model = [objectArray objectAtIndex:i];
[aPath lineToPoint:NSMakePoint([model x] * factorX, [model y] * factorY)];
} else if([[[objectArray objectAtIndex:i] type]isEqualToString:@"RelativeLineTo"]){
debugLog(@"Drawing a relative path lineto");
RelativeLineToModel *model = [objectArray objectAtIndex:i];
[aPath relativeLineToPoint:NSMakePoint([model x] * factorX, [model y] * factorY)];
//[model release];
} else if([[[objectArray objectAtIndex:i] type]isEqualToString:@"AbsoluteCurveTo"]){
debugLog(@"Drawing an absolute path lineto");
AbsoluteCubicBezierCurveToModel *model = [objectArray objectAtIndex:i];
[aPath curveToPoint:NSMakePoint([model x] * factorX, [model y] * factorY) controlPoint1:NSMakePoint([model c1x] * factorX, [model c1y] * factorY) controlPoint2:NSMakePoint([model c2x] * factorX, [model c2y] * factorY)];
} else if([[[objectArray objectAtIndex:i] type]isEqualToString:@"RelativeCurveTo"]){
RelativeCubicBezierCurveToModel *model = [objectArray objectAtIndex:i];
[aPath relativeCurveToPoint:NSMakePoint([model x] * factorX, [model y] * factorY) controlPoint1:NSMakePoint([model c1x] * factorX, [model c1y] * factorY) controlPoint2:NSMakePoint([model c2x] * factorX, [model c2y] * factorY)];
} else if([[[objectArray objectAtIndex:i] type]isEqualToString:@"ClosePath"]){
[aPath closePath];
}
}

[aPath retain];
//debugLog(@"%@", aPath);
[self setNeedsDisplay:YES];
}

- (void)drawRect:(NSRect)rect
{
//debugLog(@"%@", aPath);
[[NSColor whiteColor] set];
NSRectFill( rect );
[[NSColor blackColor] set];
[aPath stroke];
}

最佳答案

解决方案非常简单......在长贝塞尔曲线中,值按上述方式连接,在输入新的曲线坐标之前我没有清除旧的数据模型。现在一切都很好。

关于objective-c - NSBezierPath 三次贝塞尔曲线To 看起来像一条直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5061279/

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