gpt4 book ai didi

swift 4 : Opacity constantly overlaps in one stroke (Drawing App)

转载 作者:行者123 更新时间:2023-11-30 12:03:24 25 4
gpt4 key购买 nike

不透明度在一笔中重叠,而不是一笔实心不透明笔划。 Opacity Stroke

我尝试修改一些上下文,甚至删除一些上下文,但是这些都没有帮助(我已将其恢复到原始状态)。我的目标是尝试使用标记工具进行绘制,与不透明度为 1 的铅笔工具相比,不透明度约为 0.5。当我使用标记时,我得到的都是如图所示的恒定点,我相信即使我没有抬起手指,只需轻轻一扫,它们都是单独的笔画。

如果有人对此有任何了解,我真的需要一些帮助(:

这是我的核心图形代码。

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
swiped = true
if let touch = touches.first {
let currentPoint = touch.preciseLocation(in: self.view)
drawLines(fromPoint: lastPoint, toPoint: currentPoint)
lastPoint = currentPoint
tool.center = currentPoint

}
}
func drawLines(fromPoint: CGPoint, toPoint: CGPoint) {
UIGraphicsBeginImageContext(self.view.frame.size)
imageView.image?.draw(in: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height))

let context = UIGraphicsGetCurrentContext()
context?.move(to: CGPoint(x: fromPoint.x, y: fromPoint.y))
context?.addLine(to: CGPoint(x: toPoint.x, y: toPoint.y))
context?.setStrokeColor(UIColor(red: red, green: green, blue: blue, alpha: opacityValue).cgColor)
context?.setBlendMode(CGBlendMode.normal)
context?.setLineJoin(CGLineJoin.bevel)
context?.setLineCap(CGLineCap.round)
context?.setLineWidth(brushSize)
context?.strokePath()

imageView.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
if !swiped {
drawLines(fromPoint: lastPoint, toPoint: currentPoint)

}
}

override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
touchesEnded(touches, with: event)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()

}

最佳答案

问题在于您将每个线段作为单独的线段绘制到图像上。由于每个片段重叠并且您使用部分透明的颜色,因此重叠的透明区域显得更暗。

一种解决方案是保留所有已绘制点的数组(而不仅仅是最新和之前的点)。然后构造一条由所有点之间的所有线段组成的单个路径,然后描画该单个路径。这将消除较暗的重叠区域。

关于 swift 4 : Opacity constantly overlaps in one stroke (Drawing App),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46944468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com