Monday, 15 June 2015

javascript - Sometimes the HTML5 canvas works and displays the image and sometimes it doesn't on IE9 -



javascript - Sometimes the HTML5 canvas works and displays the image and sometimes it doesn't on IE9 -

sometimes html5 canvas works , displays image , doesn't on ie9 webpage: https://www.barnwellmd.com/paindiagram/paindiagram.html. works in firefox , chrome.

can see doing wrong?

here js code loads image:

function init () { // find canvas element. canvas = document.getelementbyid('imageview'); if (!canvas) { alert('error: cannot find canvas element!'); return; } if (!canvas.getcontext) { alert('error: no canvas.getcontext!'); return; } // 2d canvas context. context = canvas.getcontext('2d'); if (!context) { alert('error: failed getcontext!'); return; } var img=new image(); img.onload = function(){ context.drawimage(img,0,0); imagedata = context.getimagedata(0, 0, 700, 643); pixels = imagedata.data; }; img.src="paindiagram.png"; ...

i think if swap these 2 code blocks, how have done below should fixed:

// 2d canvas context. context = canvas.getcontext('2d'); if (!context) { alert('error: failed getcontext!'); return; } if (!canvas.getcontext) { alert('error: no canvas.getcontext!'); return; }

javascript html canvas

No comments:

Post a Comment