bonjour!
i'm trying make use of canvas element under reactjs. i'm getting error when call drawimage(). work except drawimage().. ?
uncaught typeerror: failed execute 'drawimage' on 'canvasrenderingcontext2d': provided value not of type '(htmlimageelement or htmlvideoelement or htmlcanvaselement or imagebitmap)'
var canvas = react.createclass({ componentdidupdate: function() { console.log("componentdidupdate"); }, componentdidmount: function() { var context = this.getdomnode().getcontext('2d'); this.paint(context); }, paint: function(context) { context.save(); context.fillstyle = '#f00'; context.fillrect(0, 0, 400, 400); context.drawimage("image.jpg", 0, 0); context.restore(); }, render: function(){ return <canvas width={400} height={400} />; } });
are sure image.jpg has been loaded before call drawimage()?
from w3schools:
note: cannot call drawimage() method before image has loaded. ensure image has been loaded, can call drawimage() window.onload() or document.getelementbyid("imageid").onload.
Comments
Post a Comment