1
由於某種原因,下面的代碼將不起作用。它停在與getImageData
一致的線上。 IE9會拋出此錯誤:SCRIPT5022: DOM Exception: INDEX_SIZE_ERR (1)
。有解決這個問題的解決方法嗎?但是,它同時適用於Chrome和FF。IE9在HTML5 Canvas中存在問題getImageData()函數
//Select our canvas and context
var canvas = document.getElementById("imageCanvas");
var context = canvas.getContext('2d');
//Select the image from the DOM
var selectedImage = document.getElementById("image");
//Draw the image to the canvas then read in the data
context.drawImage(selectedImage, 0, 0);
var originalLakeImageData = context.getImageData(0,0, width, height);
//Image data is now stored in an array in the form
//originalLakeImageData.data = [r1, g1, b1, a1, r2, g2, b2, a2....]
注意:上面的代碼不是我的代碼。來源是here。但是,我的問題與此示例相同。要查看錯誤IE9,請嘗試此操作link
錯誤發生時'width'和'height'的值是什麼? – dqhendricks
當時的寬度和高度爲0 - 在調試器中查找。也許你可以在這裏找到提示:http://jimdiesel.wordpress.com/2009/04/30/javasvript-image-dimension-issue-in-internet-explorer/ – Alex