【发布时间】:2015-07-07 03:12:43
【问题描述】:
我正在创建一个演示 IOS 应用程序,它将是一个简单的绘图应用程序。我已经使用 Quartz 2D 创建了一个基本的应用程序。但是,绘制的线条非常参差不齐。我正在寻找一种方法来应用抗锯齿或混合以使线条平滑。 drawLineFrom 看起来像这样:
func drawLineFrom(fromPoint: CGPoint, toPoint: CGPoint) {
UIGraphicsBeginImageContext(view.frame.size)
let context = UIGraphicsGetCurrentContext()
tempImageView.image?.drawInRect(CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height))
CGContextMoveToPoint(context, fromPoint.x, fromPoint.y)
CGContextAddLineToPoint(context, toPoint.x, toPoint.y)
CGContextSetAllowsAntialiasing(context, true)
CGContextSetShouldAntialias(context, true)
CGContextSetLineCap(context, kCGLineCapRound)
CGContextSetLineWidth(context, brushWidth)
CGContextSetRGBStrokeColor(context, red, green, blue, 1.0)
CGContextSetBlendMode(context, kCGBlendModeNormal)
CGContextStrokePath(context)
tempImageView.image = UIGraphicsGetImageFromCurrentImageContext()
tempImageView.alpha = opacity
UIGraphicsEndImageContext()
}
项目可以在这里找到:https://github.com/BananaSplitio/OpenSketch
感谢您的帮助!
【问题讨论】:
标签: ios swift ipad core-graphics quartz-2d