0
我想克隆面料js画布并继续编辑克隆画布中的现有面料js对象,但它不起作用。它显示setBackgroundImage是未定义的。面料js克隆画布并继续编辑
$('#btnClick').on('click touchstart', function() {
var canvas = document.getElementsByTagName("canvas");
// canvas context
var context = canvas[0].getContext("2d");
// get the current ImageData for the canvas
var data = context.getImageData(0, 0, canvas[0].width, canvas[0].height);
// store the current globalCompositeOperation
var compositeOperation = context.globalCompositeOperation;
// set to draw behind current content
context.globalCompositeOperation = "destination-over";
//set background color
context.fillStyle = "#FFFFFF";
// draw background/rectangle on entire canvas
context.fillRect(0,0,canvas[0].width,canvas[0].height);
var tempCanvas = document.createElement("canvas"),
tCtx = tempCanvas.getContext("2d");
tempCanvas.width = 640;
tempCanvas.height = 480;
tempCanvas.setBackgroundImage('');
}
<canvas><canvas>
JavaScript的画布上没有任何的API了setBackgroundImage。可能你应该通过创建它来使用这个画布的结构对象 – Fisherman
,尽管你可以通过CSS来为画布添加背景'''canvas {background:url(img.jpg)}''' – Fisherman