抗锯齿和更新路径会导致线条比预期更粗
这个问题很难解释,但这里是:
我正在制作一个绘画程序,将路径绘制到具有纹理背景的画布上。每个笔划都存储为一条路径,当用户在屏幕上移动触控笔时,该路径会更新。当路径更新时,我在画布上调用drawpath。问题在于,在每次移动事件中,路径都会在画布上的现有线条上绘制,因此其上的抗锯齿会使现有线条变暗,并使其看起来比预期更粗、更锯齿。
我有一个解决方案,我存储旧的画布(没有活动路径的画布)并在其上保留另一个透明画布。我会清除顶部画布并在每个移动事件上重新绘制路径,然后将两个画布绘制在一起。但这使得程序变得如此缓慢,以至于路径看起来很糟糕 - 你可以看出绘图远远落后于手写笔的移动。
有什么方法可以使 A)更快地绘制/清除多个画布或 B)使抗锯齿不会在多次重绘时造成混乱?
The problem is pretty complicated to explain but here goes:
I'm making a paint program that draws paths onto a canvas with textured background. Each stroke is stored as a path that updates as the user moves the stylus across the screen. When the path is updated I call drawpath on the canvas. The problem is that on each move event, the path is drawn over the existing line on the canvas, so the antialiasing on it darkens the existing line and make it appear thicker and jaggier than expected.
I had a solution where I store the older canvas (the one without the active path) and keep another transparent canvas on top of that. I would clear the top canvas and redraw the path on each move event, and then draw both canvases together. BUT that makes the program so slow that the paths look terrible - you can tell the drawing is lagging way behind the stylus movements.
Is there any way to make either A) drawing / clearing multiple canvases faster or B) make antialiasing not mess up on multiple redraws?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了。
它是如此简单,我简直不敢相信我竟然被困住了。
onDraw()
中使用的“canvas”每次都会自动擦除,因此我只需使用onDraw() 中当前更新的路径调用
功能,无需额外费用。canvas.drawPath()
)Figured out.
It was so simple I can't believe I got stuck on it.
The "canvas" used in
onDraw()
is automatically erased every time, so I just calledcanvas.drawPath()
with the currently updating path in theonDraw()
function, at no extra cost.