0
我已經知道如何在2點之間劃一條線,但是線看起來並不那麼光滑。我能做些什麼來使它更平滑?謝謝。如何平滑iOS中2點之間的界限?
- (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();
}
你是什麼意思「不光滑」?你有兩點,你會得到他們之間的一條直線。什麼順利呢? – Abizern
試試這個http://tonyngo.net/2011/09/smooth-line-drawing-in-ios/ – Liolik
@Abizern:這條線有點鋸齒。 –