【发布时间】:2017-03-19 07:05:08
【问题描述】:
我想用织物 js 克隆画布并继续在克隆画布中编辑现有的织物 js 对象,但它不起作用。它表明 setBackgroundImage 未定义。
$('#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 画布没有任何 setBackgroundImage api。可能你应该通过创建它来使用这个画布的织物对象
-
虽然你可以通过 css
canvas { background:url(img.jpg) }为画布添加背景
标签: javascript canvas fabricjs