HTML canvas transform() 方法

返回上一级

HTML canvas transform() 方法用于替换当前的变换矩阵

画布上的每个对象都拥有一个当前的变换矩阵

transform() 方法使用下面描述的矩阵来操作当前的变换矩阵

a c e
b d f
0 0 1

换句话说,transform() 允许缩放、旋转、移动并倾斜当前的环境

该变换只会影响 transform() 方法调用之后的绘图

transform() 方法的行为相对于由 rotate()、scale()、translate() 或 transform() 完成的其他变换

例如:如果我们已经将绘图设置为放到两倍,则 transform() 方法会把绘图放大两倍,我们的绘图最终将放大四倍

请查看 setTransform() 方法,它不会相对于其他变换来发生行为

JavaScript 语法

context.transform(a,b,c,d,e,f);

参数列表

参数 描述
a 水平缩放绘图
b 水平倾斜绘图
c 垂直倾斜绘图
d 垂直缩放绘图
e 水平移动绘图
f 垂直移动绘图

浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 transform() 方法

Internet Explorer 8 及之前的版本不支持 <canvas> 元素

范例

绘制一个矩形,通过 transform() 添加一个新的变换矩阵,再次绘制矩形,添加一个新的变换矩阵,然后再次绘制矩形

每次调用 transform() 时,它都会在前一个变换矩阵上构建

你的浏览器不支持 <canvas> 标签
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="yellow";
ctx.fillRect(0,0,250,100)
ctx.transform(1,0.5,-0.5,1,30,10);
ctx.fillStyle="red";
ctx.fillRect(0,0,250,100);
ctx.transform(1,0.5,-0.5,1,30,10);
ctx.fillStyle="blue";
ctx.fillRect(0,0,250,100);

运行范例 »

返回上一级

HTML 全部标签

关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.