抗锯齿和更新路径会导致线条比预期更粗

发布于 2024-11-27 12:10:03 字数 366 浏览 0 评论 0原文

这个问题很难解释,但这里是:

我正在制作一个绘画程序,将路径绘制到具有纹理背景的画布上。每个笔划都存储为一条路径,当用户在屏幕上移动触控笔时,该路径会更新。当路径更新时,我在画布上调用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澉约 2024-12-04 12:10:03

想通了。

它是如此简单,我简直不敢相信我竟然被困住了。

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 called canvas.drawPath() with the currently updating path in the onDraw() function, at no extra cost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文