
- 0133技术站
- 联系QQ:88526
- QQ交流群
- 微信公众号

HTML canvas setTransform() 方法
定义和用法
画布上的每个对象都拥有一个当前的变换矩阵。
setTransform() 方法把当前的变换矩阵重置为单位矩阵,然后以相同的参数运行 transform()。
换句话说,setTransform() 允许您缩放、旋转、移动并倾斜当前的环境。
注意:该变换只会影响 setTransform() 方法调用之后的绘图。
JavaScript 语法:
context.setTransform(a,b,c,d,e,f);
浏览器支持





Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 setTransform() 方法。
注意:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。
参数值
| 参数 | 描述 |
|---|---|
| a | 水平缩放绘图。 |
| b | 水平倾斜绘图。 |
| c | 垂直倾斜绘图。 |
| d | 垂直缩放绘图。 |
| e | 水平移动绘图。 |
| f | 垂直移动绘图。 |
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
您的浏览器不支持 HTML5 canvas 标签。
</canvas>
<script>
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);
</script>
</body>
</html>点击 "运行实例" 按钮查看在线实例
推荐手册