• canvas旋转,水平垂直镜像


    1. //旋转镜像
    2. ctx.setTransform(1, 0, 0, 1, 0, 0); //恢复坐标系
    3. ctx.translate(
    4. location[i].left -
    5. component.show.Position.Left.value +
    6. location[i].width / 2,
    7. location[i].top -
    8. component.show.Position.Top.value +
    9. location[i].height / 2
    10. );//以中心点为坐标原点旋转,即顶点的x值+宽度的一半
    11. ctx.rotate((location[i].rotate * Math.PI) / 180);//旋转角度
    12. ctx.translate(
    13. -(
    14. location[i].left -
    15. component.show.Position.Left.value +
    16. location[i].width / 2
    17. ),
    18. -(
    19. location[i].top -
    20. component.show.Position.Top.value +
    21. location[i].height / 2
    22. )
    23. );//以中心点为坐标原点旋转,即顶点的x值+宽度的一半整体的负数值
    24. //如果有翻转,分别是垂直和水平
    25. if(location[i].rotateY===180){
    26. //垂直镜像 (宽度+顶点x坐标*2,0)
    27. ctx.translate(location[i].width+ (location[i].left - component.show.Position.Left.value)*2, 0);
    28. ctx.scale(-1, 1);
    29. //恢复旋转的角度与旋转同,角度为旋转时的2倍
    30. ctx.translate(
    31. location[i].left -
    32. component.show.Position.Left.value +
    33. location[i].width / 2,
    34. location[i].top -
    35. component.show.Position.Top.value +
    36. location[i].height / 2
    37. );
    38. ctx.rotate(2*(location[i].rotate * Math.PI) / 180);
    39. ctx.translate(
    40. -(
    41. location[i].left -
    42. component.show.Position.Left.value +
    43. location[i].width / 2
    44. ),
    45. -(
    46. location[i].top -
    47. component.show.Position.Top.value +
    48. location[i].height / 2
    49. )
    50. );
    51. }
    52. console.log('location[i].rotateY',location[i].rotateY,location[i].rotate);
    53. if(location[i].rotateX===180){
    54. //垂直镜像 (0,高度+顶点y坐标*2)
    55. ctx.translate(0,location[i].height+ (location[i].top - component.show.Position.Top.value)*2);
    56. ctx.scale(1, -1);
    57. //恢复同旋转,角度2倍
    58. ctx.translate(
    59. location[i].left -
    60. component.show.Position.Left.value +
    61. location[i].width / 2,
    62. location[i].top -
    63. component.show.Position.Top.value +
    64. location[i].height / 2
    65. );
    66. ctx.rotate((2*location[i].rotate * Math.PI) / 180);
    67. ctx.translate(
    68. -(
    69. location[i].left -
    70. component.show.Position.Left.value +
    71. location[i].width / 2
    72. ),
    73. -(
    74. location[i].top -
    75. component.show.Position.Top.value +
    76. location[i].height / 2
    77. )
    78. );
    79. }
    80. ctx.drawImage(
    81. img,
    82. location[i].left - component.show.Position.Left.value,
    83. location[i].top - component.show.Position.Top.value,
    84. location[i].width,
    85. location[i].height
    86. );

     

  • 相关阅读:
    贝加莱使用教程1-创建X20工程和点亮LED灯
    【漏洞复现】H3C路由器信息泄露任意用户登录
    Excel VSTO开发8 -相关控件
    跨境电商系统源码分享,解决你的电商难题
    MMDetection自定义双主干Transformer模型(一)
    华为机试 - 水仙花数Ⅱ
    【数据库】分组数据 GROUP BY、HAVING
    偏微分方程的人工智能
    来自北大算法课的Leetcode题解:8. 字符串转换整数(atoi)
    鹅厂3.5亿打水漂,又一款产品黄了
  • 原文地址:https://blog.csdn.net/qq_51389137/article/details/125438726