画布不能旋转图像

时间:2014-05-26 10:12:10

标签: image canvas rotation

为什么这段代码不起作用?我想获得与方向相对应的线和末端箭头。

<canvas id="myCanvas" width="1024" height="585">
<script>
    var canvas = document.getElementById('myCanvas')
        , context = canvas.getContext('2d')
        , image = new Image();

    image.src = "strzalka.png";

    image.onload = function() {   
        context.beginPath();
        context.moveTo(400, 400);
        context.lineTo(200, 200);
        context.stroke();

        var degrees = (400 - 200) / (400 - 200);

        context.save();
        context.rotate(degrees);
        context.drawImage(image, 200-10, 200-10);
        context.restore();
    }
</script>

0 个答案:

没有答案