问题
I am using Fabric.js
and Canvas
to design some cards. I need to strech the background image to the canvas size. But it is not working. Below is my code.
SCRIPT
<script src="/fabric/dist/fabric.js"></script>
...
<script>
function myBg(){
var canvas = this.__canvas = new fabric.Canvas('myCanvas');
canvas.setBackgroundImage('images/download.jpg', canvas.renderAll.bind(canvas),
{
backgroundImageOpacity: 0.5,
backgroundImageStretch: true
});
//this.__canvases.push(canvas); this gives me 'Uncaught TypeError: Cannot read property 'push' of undefined'
canvas.renderAll();
}
</script>
HTML
<canvas id="myCanvas" width="544px" height="682px">
<div id="Layer4" onclick="myBg();"><img src="images/Layer4.png"> </div>
It is loading the image but not streching! Any clues?
来源:https://stackoverflow.com/questions/29005435/strech-the-background-image-to-canvas-size-with-fabric-js