• 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. );

     

  • 相关阅读:
    世微 宽电压降压 DC-DC 电源管理芯片 以太网平衡车工业控制电源驱动12V6A AP8854
    MySQL之函数
    教你手机变流畅的方法
    2. 加载与存储指令
    深入理解算法:从基础到实践
    vue-lazyload图片懒加载
    硅谷产品实战学习感触
    Python-列表简介
    阳离子卟啉化合物修饰氯甲基化交联/聚乙烯基吡啶阳离子功能化聚苯乙烯微球的研究
    vue3 - 使用reactive定义响应式数据进行赋值时,视图没有改变,值已经改变的解决方案
  • 原文地址:https://blog.csdn.net/qq_51389137/article/details/125438726