2
我使用此功能复制旧帆布新建画布拷贝画布其他画布
function cloneCanvas(oldCanvas) {
//create a new canvas
var newCanvas = document.createElement('canvas');
var context = newCanvas.getContext('2d');
//set dimensions
newCanvas.width = oldCanvas.width;
newCanvas.height = oldCanvas.height;
//apply the old canvas to the new one
context.drawImage(oldCanvas, 0, 0);
//return the new canvas
return newCanvas;
}
我用这样
var oldCanvas = $(this).parent().parent().find('td:first-child canvas')
$("div.previewImg").append(cloneCanvas(oldCanvas))
这个功能,但我得到这个错误:(
Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided
请帮助我,我该如何解决这个错误
谢谢
canvasDataImg = oldCanvasContext.toDataURL(“image/png”);如果有跨域的图像可能会失败。最好使用context.drawImage(oldCanvas,0,0); – Madan 2014-12-14 17:46:31