翻转、移动、平移、放大、缩小
- var canvas = document.getElementById('canvas'); if (canvas.getContext) {
- var context = canvas.getContext('2d'); // 放大与缩小
- context.beginPath(); context.strokeStyle = "#000000";
- context.strokeRect(10,10,150,100);
- // 放大3倍 context.scale(3,3);
- context.beginPath(); context.strokeStyle = '#cccccc';
- context.strokeRect(10,10,150,100)
- // 缩小 context.scale(0.5,0.5);
- context.beginPath(); context.strokeStyle = '#cccccc';
- context.strokeRect(10,10,150,100)
- // 翻转 var img = new Image();
- img.src = 'images/1.jpg'; img.onload = function(){
- context.drawImage(img, 10,10); context.scale(1, -1);
- context.drawImage(img, 0, -500); }
- // 平移 context.beginPath();
- context.strokeStyle = '#000000'; context.strokeRect(10,101,150,100);
- // x移动 50 y 移动100 context.translate(50,100);
- context.beginPath(); context.strokeStyle = '#cccccc';
- context.strokeRect(10,10,150,100); // 旋转
- context.beginPath(); context.strokeStyle = '#000000';
- context.strokeRect(200,50,100,50); // 默认旋转是根据0,0中心,使用translate可以按照自己的设置的中心旋转
- context.translate(250,75);
- context.rotate(45 * Math.PI /180); context.translate(-250, -75);
- context.beginPath();
- context.strokeStyle = '#cccccc'; context.strokeRect(200,50,100,50);
- // transform 矩阵
- context.beginPath(); context.strokeStyle = '#000000';
- context.strokeRect(10,10,150,100);
- context.transform(3,0,0,3,0,0); context.beginPath();
- context.strokeStyle = '#cccccc'; context.strokeRect(10,10,150,100);
- }
相关文章
大家在看
-

福昕阅读器如何复制文字
2023-03-02
0万阅读
-

Dubbo 系列JDK SPI 原理解析
2023-02-24
0万阅读
-

欲为王者至尊 888元志美4倍速DVD刻录机评测
2023-02-22
6万阅读
-

拼音标注能手--中华拼读王
2023-02-17
10万阅读
-

360随身WiFi怎么设置隐藏信号 360随身wifi隐藏信号
2023-02-12
9万阅读
-

怎么用酷盘分享文件给好友
2023-02-11
12万阅读
-

企业应如何防范内存抓取恶意软件
2023-02-10
6万阅读
-

如何知道电脑是否含有病毒
2023-02-09
8万阅读
-

美图秀秀让你的国庆旅游照片更出彩
2023-01-16
9万阅读
-

u启动怎么用 U启动使用教程
2023-01-14
4万阅读
-

福昕阅读器如何复制文字
2023-03-02
0万阅读
-

Dubbo 系列JDK SPI 原理解析
2023-02-24
0万阅读
-

欲为王者至尊 888元志美4倍速DVD刻录机评测
2023-02-22
6万阅读
-

拼音标注能手--中华拼读王
2023-02-17
10万阅读
-

360随身WiFi怎么设置隐藏信号 360随身wifi隐藏信号
2023-02-12
9万阅读
-

怎么用酷盘分享文件给好友
2023-02-11
12万阅读
-

企业应如何防范内存抓取恶意软件
2023-02-10
6万阅读
-

如何知道电脑是否含有病毒
2023-02-09
8万阅读
-

美图秀秀让你的国庆旅游照片更出彩
2023-01-16
9万阅读
-

u启动怎么用 U启动使用教程
2023-01-14
4万阅读
