0

HTML5 キャンバスが機能して画像が表示される場合と、次の Web ページの IE9 では表示されない場合があります: https://www.barnwellmd.com/PainDiagram/PainDiagram.html。Firefox と Chrome では常に動作します。

誰かが私が間違っていることを見ることができますか?

画像をロードする js コードは次のとおりです。

function init () {
// Find the canvas element.
canvas = document.getElementById('imageView');
if (!canvas) {
  alert('Error: I cannot find the canvas element!');
  return;
}

if (!canvas.getContext) {
  alert('Error: no canvas.getContext!');
  return;
}

// Get the 2D canvas context.
context = canvas.getContext('2d');
if (!context) {
  alert('Error: failed to 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";
    ...
4

1 に答える 1

0

これらの2つのコードブロックを交換すると、以下のように修正されるはずです。

// Get the 2D canvas context.
context = canvas.getContext('2d');
if (!context) {
  alert('Error: failed to getContext!');
  return;
}


if (!canvas.getContext) {
  alert('Error: no canvas.getContext!');
  return;
}
于 2013-02-10T06:45:51.770 に答える