Flip images at 30 degrees?

前端 未结 3 622
栀梦
栀梦 2020-12-22 13:30

In canvas I know that I can flip images horizontally and vertically by doing this:

vc.scale(-1, -1)

But is there some way to flip an image

3条回答
  •  孤城傲影
    2020-12-22 13:42

    Yes, you can accomplish this using the rotate() method of canvas :

    var ctx = document.getElementById("myCanvas").getContext("2d");
    var img = new Image();
    img.src = "http://photos.the-scientist.com/articleImages/48000/48607-1-t.jpg";
    img.onload = function() {
        ctx.rotate(30 * Math.PI / 180);
        ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2);
        ctx.scale(1, -1);
        ctx.drawImage(img, -65, 65);
    }

提交回复
热议问题