html5 图片旋转

找了很久,终于找到图片旋转的方法了,现在向大家分享一下!

<!DOCTYPE HTML>
<html> 
    <head> 
        <title>test rotate</title> 
        <script type="text/javascript"> 
            function startup() { 
                var canvas = document.getElementById('canvas'); 
                var ctx = canvas.getContext('2d'); 
                var img = new Image();
                img.src = 'Penguins.jpg';
                img.onload = function() {
                ctx.translate(img.width / 2, img.height / 2); 
                    ctx.rotate(30 * Math.PI / 180); 
                    ctx.drawImage(img, 0, 0, 164, 164); 
                } 
            } 
        </script> 
    </head> 
    <body onload='startup();'> 
     <div >
        <canvas ></canvas> 
     </div>
    </body> 
</html> 

  效果图:

html5 图片旋转

相关文章:

  • 2021-10-22
  • 2022-01-07
  • 2021-06-07
  • 2021-09-16
  • 2022-12-23
  • 2021-05-22
  • 2021-10-17
猜你喜欢
  • 2022-01-17
  • 2021-11-03
  • 2022-02-17
  • 2021-11-26
  • 2021-04-03
  • 2022-12-23
相关资源
相似解决方案