HTML canvas setTransform() 方法
实例
绘制个矩形 通过 setTransform() 重置并创建新的变换矩阵 再次绘制矩形 重置并创建新的变换矩阵 然后再次绘制矩形。请注意 每当您调用 setTransform() 时 它都会重置前个变换矩阵然后构建新的矩阵 因此在下面的例子中 不会显示红色矩形 因为它在蓝色矩形下面:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="yellow";
ctx.fillRect(0,0,250,100)
ctx.setTransform(1,0.5,-0.5,1,30,10);
ctx.fillStyle="red";
ctx.fillRect(0,0,250,100);
ctx.setTransform(1,0.5,-0.5,1,30,10);
ctx.fillStyle="blue";
ctx.fillRect(0,0,250,100);
var ctx=c.getContext("2d");
ctx.fillStyle="yellow";
ctx.fillRect(0,0,250,100)
ctx.setTransform(1,0.5,-0.5,1,30,10);
ctx.fillStyle="red";
ctx.fillRect(0,0,250,100);
ctx.setTransform(1,0.5,-0.5,1,30,10);
ctx.fillStyle="blue";
ctx.fillRect(0,0,250,100);
尝试一下 »
浏览器支持
Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 setTransform()方法。
注意:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。
定义和用法
画布上的每个对象都拥有个当前的变换矩阵。
setTransform() 方法把当前的变换矩阵重置为单位矩阵 然后以相同的参数运行 transform()。
换句话说 setTransform() 允许您缩放、旋转、移动并倾斜当前的环境。
注意:该变换只会影响 setTransform() 方法调用之后的绘图。
JavaScript 语法: | context.setTransform(a,b,c,d,e,f); |
---|
参数值
参数 | 描述 |
---|---|
a | 水平缩放绘图。 |
b | 水平倾斜绘图。 |
c | 垂直倾斜绘图。 |
d | 垂直缩放绘图。 |
e | 水平移动绘图。 |
f | 垂直移动绘图。 |

尊贵的董事大人
英文标题不为空时 视为本栏投稿
需要关键字 描述 英文标题