国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > HTML5 > 正文

HTML5 Canvas實(shí)現(xiàn)圖片縮放、翻轉(zhuǎn)、顏色漸變的代碼示例

2024-09-05 07:21:24
字體:
供稿:網(wǎng)友

翻轉(zhuǎn)、移動(dòng)、平移、放大、縮小

XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. var canvas = document.getElementById('canvas');   
  2. if (canvas.getContext) {   
  3.     var context = canvas.getContext('2d');   
  4.     // 放大與縮小   
  5.     context.beginPath();   
  6.     context.strokeStyle = "#000000";   
  7.     context.strokeRect(10,10,150,100);   
  8.         
  9.     // 放大3倍   
  10.     context.scale(3,3);   
  11.     context.beginPath();   
  12.     context.strokeStyle = '#cccccc';   
  13.     context.strokeRect(10,10,150,100)   
  14.         
  15.     // 縮小   
  16.     context.scale(0.5,0.5);   
  17.     context.beginPath();   
  18.     context.strokeStyle = '#cccccc';   
  19.     context.strokeRect(10,10,150,100)   
  20.         
  21.      // 翻轉(zhuǎn)   
  22.     var img = new Image();   
  23.     img.src = 'images/1.jpg';   
  24.     img.onload = function(){   
  25.         context.drawImage(img, 10,10);           
  26.         context.scale(1, -1);   
  27.         context.drawImage(img, 0, -500);   
  28.     }   
  29.     // 平移   
  30.     context.beginPath();   
  31.     context.strokeStyle = '#000000';   
  32.     context.strokeRect(10,101,150,100);   
  33.     // x移動(dòng) 50  y 移動(dòng)100   
  34.     context.translate(50,100);   
  35.     context.beginPath();   
  36.     context.strokeStyle = '#cccccc';   
  37.     context.strokeRect(10,10,150,100);   
  38.     // 旋轉(zhuǎn)   
  39.     context.beginPath();   
  40.     context.strokeStyle = '#000000';   
  41.     context.strokeRect(200,50,100,50);   
  42.     // 默認(rèn)旋轉(zhuǎn)是根據(jù)0,0中心,使用translate可以按照自己的設(shè)置的中心旋轉(zhuǎn)   
  43.     context.translate(250,75);   
  44.        
  45.     context.rotate(45 * Math.PI /180);   
  46.     context.translate(-250, -75);   
  47.   
  48.     context.beginPath();   
  49.     context.strokeStyle = '#cccccc';   
  50.     context.strokeRect(200,50,100,50);   
  51.         
  52.     // transform 矩陣   
  53.     context.beginPath();   
  54.     context.strokeStyle = '#000000';   
  55.     context.strokeRect(10,10,150,100);   
  56.        
  57.     context.transform(3,0,0,3,0,0);   
  58.     context.beginPath();   
  59.     context.strokeStyle = '#cccccc';   
  60.     context.strokeRect(10,10,150,100);   
  61.         
  62. }  

漸變、圖像組合效果、顏色翻轉(zhuǎn)

XML/HTML Code復(fù)制內(nèi)容到剪貼板
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 广水市| 辽宁省| 东阿县| 留坝县| 峨眉山市| 惠东县| 泰宁县| 肃宁县| 英山县| 顺平县| 本溪| 岑溪市| 承德县| 汤阴县| 邻水| 金塔县| 遵化市| 天祝| 定兴县| 阜宁县| 梧州市| 闽清县| 台南县| 横山县| 阳谷县| 杭州市| 同德县| 贵港市| 贵州省| 吐鲁番市| 邵武市| 泽普县| 孟州市| 吉首市| 昂仁县| 天祝| 塔城市| 巴东县| 肃宁县| 洛南县| 腾冲县|