gpt4 book ai didi

ios - 如何平滑 iOS 中 2 点之间的线?

转载 作者:行者123 更新时间:2023-11-28 20:18:34 29 4
gpt4 key购买 nike

我已经知道如何在两点之间画一条线,但这条线似乎不太平滑。我该怎么做才能让它更顺畅?谢谢你。

- (void)drawLineFrom:(CGPoint)start To:(CGPoint)end {
// begin image context
UIGraphicsBeginImageContext(self.imageLineView.frame.size);

// define image rect for drawing
[self.imageLineView.image drawInRect:CGRectMake(0, 0, imageLineView.frame.size.width, imageLineView.frame.size.height)];

// set line properties
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0f);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0f, .0f, .0f, 1.0);

// move context to start point
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), start.x, start.y);

// define path to end point
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), end.x, end.y);

// stroke path
CGContextStrokePath(UIGraphicsGetCurrentContext());

// flush context to be sure all drawing operations were processed
CGContextFlush(UIGraphicsGetCurrentContext());

// get UIImage from context and pass it to our image view
imageLineView.image = UIGraphicsGetImageFromCurrentImageContext();

// end image context
UIGraphicsEndImageContext();
}

enter image description here

最佳答案

您可以使用贝塞尔路径绘制平滑的线。

您可以在此处获得更多信息。 Bézier Paths

关于ios - 如何平滑 iOS 中 2 点之间的线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16892790/

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