翻轉(zhuǎn)、移動(dòng)、平移、放大、縮小
XML/HTML Code復(fù)制內(nèi)容到剪貼板
- 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)
- // 翻轉(zhuǎn)
- 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移動(dòng) 50 y 移動(dòng)100
- context.translate(50,100);
- context.beginPath();
- context.strokeStyle = '#cccccc';
- context.strokeRect(10,10,150,100);
- // 旋轉(zhuǎn)
- context.beginPath();
- context.strokeStyle = '#000000';
- context.strokeRect(200,50,100,50);
- // 默認(rèn)旋轉(zhuǎn)是根據(jù)0,0中心,使用translate可以按照自己的設(shè)置的中心旋轉(zhuǎn)
- 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);
- }
漸變、圖像組合效果、顏色翻轉(zhuǎn)
XML/HTML Code復(fù)制內(nèi)容到剪貼板
學(xué)習(xí)交流
- 綠毒越獄軟件 完美越獄4.21教程12-21
- htcg15怎么刷機(jī)?htcg15刷機(jī)教程12-21
- HTC hd7刷安卓2.2全教程12-21
- mpkg軟件下載和卸載的方法12-21
熱門(mén)圖片
猜你喜歡的新聞
- 最牛同桌!我考了696分我同桌考了703分
- 650分!高二女生考入北大:遺憾不能上高三
- 男生估分600只考了397 媽媽:高考雖重要,但不
- 唐尚珺回應(yīng)是否會(huì)直播帶貨:有人出100萬(wàn)想和
- 名校搶人名場(chǎng)面:清華、北大太拼了!
- 男生高考語(yǔ)文滿分!網(wǎng)友:第一次聽(tīng)說(shuō)
- 第16次參加高考!唐尚珺今年成績(jī)超600分
- 語(yǔ)文145分學(xué)霸筆記公開(kāi)字跡清秀:多閱讀,該背
- 數(shù)學(xué)滿分!四川綿陽(yáng)一男生高考710分 理綜僅扣
- 阿里全球數(shù)學(xué)競(jìng)賽選手:決賽專業(yè)性太強(qiáng),6道題



















