“getImageData”不适用于“drawImage”

时间:2013-01-15 14:02:53

标签: javascript html5

  

可能重复:
  HTML5 Canvas getImageData and Same Origin Policy

(抱歉我的英文不好:/) 这不起作用,我在我的学校和其他计算机上试过这个,但每台电脑都有这个问题...... 如果源没有'drawImage'标签,那么它就可以工作。

<!DOCTYPE html><html>
<head>
    <script>
        var img = new Image();
        img.src = "https://developer.apple.com/safaridemos/CanvasPixelManipulation/resources/tubes.jpg" ;

        window.onload = function()
            {
                var canvas = document.getElementById("canvas");
                var ctx = canvas.getContext("2d");

                ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
                alert("Draw Finished"); //its working

                var imgData = ctx.getImageData(0 ,0 ,canvas.width ,canvas.height );
                alert("Image Data Created"); //and its not
            }
    </script>
</head>
<body>
    <canvas id="canvas" height="500" width="500">
    </canvas>
</body>

0 个答案:

没有答案