Smooth jagged lines drawn by user in HTML5 canvas app?(用户在 HTML5 画布应用程序中绘制的平滑锯齿线?)
问题描述
我们有一个 HTML5 绘图应用程序,用户可以在其中使用铅笔工具绘制线条.
We have an HTML5 drawing app where users can draw lines using a pencil tool.
与基于 Flash 的绘图应用程序相比,线条的边缘略微呈锯齿状,看起来有些模糊.发生这种情况是因为用户在绘制时需要保持直线完全笔直,或者算法会感知每个像素偏差并将其投影为锯齿状边缘.
Compared to Flash-based drawing apps, the lines have slightly jagged edges and appear somewhat blurry. This happens because users need to keep the line perfectly straight while drawing, or the algorithm senses every pixel deviation and projects it as a jagged edge.
因此,无法绘制平滑、锐利的圆.
Drawing smooth, sharp circles is impossible as a result.
不知何故,其他绘图应用程序能够平滑这些锯齿状边缘,同时让用户绘制线条(直线或非直线).
Somehow, other drawing apps are able to smooth out these jagged edges while letting users draw lines (straight or not).
有没有办法让这些线条变得平滑?
Is there a way we can smooth out these lines?
演示(选择铅笔工具):http://devfiles.myopera.com/文章/649/example5.html
Demo (choose the pencil tool): http://devfiles.myopera.com/articles/649/example5.html
我们的应用使用类似的代码.
Our app uses similar code.
推荐答案
这是一个使用二次曲线和'round' lineJoin
的快速方法示例:
Here's an example of a quick way using quadratic curves and 'round' lineJoin
:
http://jsfiddle.net/NWBV4/10/
这篇关于用户在 HTML5 画布应用程序中绘制的平滑锯齿线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用户在 HTML5 画布应用程序中绘制的平滑锯齿线?


基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01