gpt4 book ai didi

javascript - 如何在 Canvas 内旋转形状?

转载 作者:行者123 更新时间:2023-11-30 18:23:12 25 4
gpt4 key购买 nike

我正在使用 canvas 加载图像:

var canvas=document.getElementById('canvas');
var context=canvas.getContext('2d');

context.scale(0.5,0.5);
canvas.setAttribute('width', tempImg.width*0.5);
canvas.setAttribute('height', tempImg.height*0.5);
context.drawImage(tempImg ,0,0,canvas.width,canvas.height);

我正在使用其他 Canvas 在运行时绘制形状:

var annCanvas=document.getElementById('annCanvas');
var annContext=annCanvas.getContext('2d');
context.beginPath();
context.lineWidth=4;
context.strokeRect(x,y,w,h);
context.stroke();

两个 Canvas 的位置都是绝对的,所以它们看起来像彼此重叠。但我想同时旋转两个 Canvas ( Angular 值 90,180,270,0)。

提前致谢

最佳答案

使用这个:

context.rotate(90); // rotates 90 deg clockwise

关于javascript - 如何在 Canvas 内旋转形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11559873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com