我创建了画布为contenteditable ='true'并将剪贴板上的图像粘贴在画布上。图像出现在画布旁边,不在画布的顶部,如下图所示。尝试将画布转换为图像时,我会看到空白图像。这是因为我的画布不能保存先前粘贴的图像。我如何获得图像?帆布contenteditable不工作
HTML
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
body{ background-color: ivory; }
canvas{border:1px solid red;}
</style>
<script>
function convert()
{
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
//ctx.fillRect(50,50,150,75);
var theImage=document.getElementById("toImage");
theImage.src=canvas.toDataURL();
}
</script>
</head>
<body>
<canvas id="canvas" width=300 height=300 contenteditable='true'></canvas>
<button type="button" onClick="convert()">Click</button>
<img id="toImage" width=300 height=300>
</body>
</html>
图片
我不认为有一个画布相关的页面编辑主机contenteditable。由于画布需要绘图命令,所以这样的编辑器肯定不会拖放。如果源图像是已复制到剪贴板的本地图像,您也会遇到CORS问题。如果你真的,真的很有野心**你可以在这里使用六种API方法编写canvas页内编辑器:http://www.whatwg.org/specs/web-apps/current -work/multipage/editing.html#editing-host – markE