我正在尝试复制剪裁画布区域的内容。我正在使用onmousemove监听器捕获给定区域,并希望在onclick事件发生时复制其内容:
var started = false;
editor_canvas.onmousemove = function (e) {
e = e || window.event;
var x = event.pageX;
var y = event.pageY;
if (!started) {
editor_context.beginPath();
editor_context.moveTo(x, y);
started = true;
return;
}
var rect = editor_canvas.getBoundingClientRect();
x = x - rect.left;
y = y - rect.top;
editor_context.lineWidth = 5;
editor_context.strokeStyle = 'red';
editor_context.lineTo(x, y);
editor_context.stroke();
};
editor_canvas.onclick = function(e) {
editor_context.clip();
}
JSFiddle:http://jsfiddle.net/0nn78uxr/