作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在 Canvas 元素上自由绘制(使用鼠标/手指),就像用铅笔进行绘画一样?
想在canvas上实现徒手画的问题有很多:
所以我认为提出一个引用问题是个好主意,其中每个答案都是社区 wiki,并且包含对一个 JavaScript 库/纯 JavaScript 如何在 Canvas 上绘画的解释。
答案应该是社区 wiki 并使用以下模板:
## [Name of library](Link to project page)
### Simple example
A basic, complete example. That means it has to contain HTML
and JavaScript. You can start with this:
<!DOCTYPE html>
<html>
<head>
<title>Simple example</title>
<script type='text/javascript' src='http://cdnjs.com/[your library]'></script>
<style type='text/css'>
#sheet {
border:1px solid black;
}
</style>
<script type='text/javascript'>
window.onload=function(){
// TODO: Adjust
}
</script>
</head>
<body>
<canvas id="sheet" width="400" height="400"></canvas>
</body>
</html>
If possible, this example should work with both, mouse and touch events.
[JSFiddle](Link to code on jsfiddle.net)
This solution works with:
<!-- Please test it the following way: Write "Hello World"
Problems that you test this way are:
* Does it work at all?
* Are lines separated?
* Does it get slow when you write too much?
-->
* Desktop computers:
* [Browser + Version list]
* Touch devices:
* [Browser + Version list] on [Device name]
### Import / Export
Some explanations how to import / export user drawn images.
### Line smoothing
Explanations about how to manipulate the line the user draws.
This can include:
* Bézier curves
* Controlling thickness of lines
最佳答案
<!DOCTYPE html>
<html>
<head>
<title>Simple example</title>
<script type='text/javascript' src='http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.4.0/fabric.min.js'></script>
<style type='text/css'>
#sheet {
border:1px solid black;
}
</style>
<script type='text/javascript'>
window.onload=function(){
var canvas = new fabric.Canvas('sheet');
canvas.isDrawingMode = true;
canvas.freeDrawingBrush.width = 5;
canvas.freeDrawingBrush.color = "#ff0000";
}
</script>
</head>
<body>
<canvas id="sheet" width="400" height="400"></canvas>
</body>
</html>
canvas.freeDrawingBrush.width
控制。canvas.freeDrawingBrush.color
控制。此解决方案适用于:
只能通过序列化整个 Canvas 来实现,请参阅Tutorial
自动完成,似乎无法停用它。
关于javascript - 如何使用 JavaScript 在 Canvas 上手绘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22891827/
我正在寻找进入 Swagger,更具体地说,swagger-codegen 工具。我在 github 和 http://swagger.io/ 中都找到了提供的信息、文档和规范。相当困惑(另外,一些指
我是一名优秀的程序员,十分优秀!