【问题标题】:Drawing Smooth lines with Quartz 2D使用 Quartz 2D 绘制平滑线条
【发布时间】: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


    【解决方案1】:

    我知道我在这里聚会迟到了,但如果你改变了:

    UIGraphicsBeginImageContext(view.frame.size)

    UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0f);

    这应该可以解决锯齿线问题。最后一个参数0.0f 指定屏幕比例。将此设置为0.0f 将自动将其设置为设备的分辨率。没有这个,它用 1 点 = 1 像素(所以非视网膜)绘制它,导致事物看起来参差不齐。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 2017-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多