iOS-在边界范围内绘制

我只想画一条封闭的路径,就像在边框内一样。

我已经在下面完成了代码,可以从洪水填充算法中找到一条封闭的路径
下面是封闭的,我只想在此封闭路径内绘制

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
    }

我已经使用混合模式作为Source In。

绘制时间太长了。

leaved_poplar 回答:iOS-在边界范围内绘制

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3008661.html

大家都在问