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