iOS-在边界限制内绘制
我只想画一条很近的路,就像在边界里一样 我已经完成了下面的代码,将从洪水填充算法中找到一条封闭路径iOS-在边界限制内绘制,ios,swift,drawing,uibezierpath,blending,Ios,Swift,Drawing,Uibezierpath,Blending,我只想画一条很近的路,就像在边界里一样 我已经完成了下面的代码,将从洪水填充算法中找到一条封闭路径 下面很近,我只想在这条近距离路径内画画 if !closePath.isEmpty { closePath.close() let context = UIGraphicsGetCurrentContext()! context.setBlendMode(.copy) context.addPath(c
下面很近,我只想在这条近距离路径内画画
if !closePath.isEmpty {
closePath.close()
let context = UIGraphicsGetCurrentContext()!
context.setBlendMode(.copy)
context.addPath(closePath.cgPath)
context.setLineCap(.round)
context.setAlpha(1.0)
context.setLineWidth(1)
context.setStrokeColor(UIColor.red.cgColor)
context.strokePath()
}
触摸移动时
override func draw(_ rect: CGRect) {
drawFloodFill(path: UIBezierPath())
// Drawing code
let context = UIGraphicsGetCurrentContext() // get your current context
context?.saveGState() // save the current state
context?.setBlendMode(.sourceIn) // change blend mode to DestinationOut (R = D * (1-Sa))
if touchEnd == true {
UIColor.orange.set()
} else {
UIColor.yellow.set();
}
drawingPath.lineWidth = 10
drawingPath.lineCapStyle = .round
drawingPath.stroke()
context?.restoreGState() // restore state of context
}
我在中使用了混合模式作为源
画画花的时间太多了