XML/HTML Code複製內容到剪貼簿
- var 畫布 = 文件.getElementByy@文件
.getElementByyId('canvas'); >-
if (canvas.getContext) {
-
var 上下文 = 畫布.getContext('2d');
- //放大與縮小
- context.beginPath();
- context.行程樣式 = "#000000""#000000"
- "#000000"
"#000000"- ;
context.中風長方形(10,10,150,100); -
-
// 放大3倍 -
context.scale(3,3); -
context.beginPath();
context.行程樣式
= - '#cccccc'
- '#cccccc';
- context.行程矩形(10,10,150,100)
-
- //縮小
- context.scale(0.5,0.5);
context.beginPath();
context.行程樣式
- = '#cccccc'
- '#cccccc'
;
- context.StrongRect(10,10,150,100)
-
// 跳
var
img-
= new new
new-
new
img.src
= - 'images/1.jpg'
- 'images/1.jpg'
'images/1.jpg'- ;
- img.onload = 函數(){🎜>函數(){ >
context.drawImage(img, 10,10);
context.scale(1, -1);
context.drawImage(img, 0, -500);
}
- // 平移
- context.beginPath();
-
context.行程樣式 = '#000000''#000000'
- '#000000'
- '#000000'
'#000000'- ;
context.中風矩形(10,101,150,100); -
// x移動 50 y 移動100 -
context.translate(50,100);
context.beginPath();
- context.行程樣式
= - '#cccccc'
- '#cccccc';
- context.中風長方形(10,10,150,100);
// 旋轉
context.beginPath();
- context.行程樣式
- = '#000000'
- '#000000'
- '#000000'
'#000000'-
'#000000'
- ;
context.中風矩形(200,50,100,50);
-
//預設旋轉是根據0,0中心,使用translate可以依照自己設定的中心旋轉
-
context.translate(250,75);
-
context.rotate(45 * Math.PI /180);
context.translate(-250, -75);
-
-
context.beginPath();
-
- context.行程樣式 =
- '#cccccc''#cccccc';
context.中風矩形(200,50,100,50);
-
// 轉換 矩陣 -
context.beginPath(); -
- context.行程樣式
= -
'#000000''#000000''#000000''#000000'
- '#000000'
;
- context.中風長方形(10,10,150,100);
-
context.transform(3,0,0,3,0,0);
context.行程樣式 =
'#cccccc''#cccccc';
context.中風長方形(10,10,150,100);
}
突變、影像組合效果、顏色切換
XML/HTML 程式碼將內容複製到剪貼簿
- var canvas = document.getElementBy>document
.getElementBy; >-
if (canvas.getContext) {
-
var context = canvas.Congetn('2d');
- // 線性繪圖漸層
- var grd = context.create
// postion 必須是0.1-1.0之間的垂直,表示漸層中顏色的地點相對地位,color表示顏色
-
grd.addColorStop(0.1, "#00ff00");
-
grd.addColorStop(0.8, "#ff0000");
-
-
- context.fillStyle =
context.fillRect(0,0, 200,100);
// 徑向漸層
-
var
- grd =
- context
grd.addColorStop(0.1, "#00ff00");
grd.addColorStop(0.8, '#ff0000');
-
context.fillStyle- =
-
context.fillRect(0,0,200,200);
// 影像組合效果
context.fillStyle- =
'#00ff00'-
'#00ff00'
- ;
context.fillRect(10,10,50,50);
// 新繪圖
//
- context.globalCompositeOperation =
-
// 只繪製新內容,並刪除所有其他內容
-
context.globalCompositeOperation = 'copy' =
'copy'- = 'copy'
= -
'copy' = 'copy' = // 圖形重疊的地方,其色彩值相減後決定
- context.globalCompositeOperation
- = 'darker' = '
// 畫布上已經有的內容只會載和其他圖形重疊的地方保留
- context.globalCompositeOperation
= - 'destination-atop' 🎜> // 參考 http://www.w3school.com.cn/htmldom/prop_canvasrenderingcontext2d_globalcompositeoperation.asp
context.beginPath();
- context.fillStyle
= - '#ff0000'
- '#ff0000';
- context.arc(50,50,30,0, 2 * Math.PI);
- context.fill();
-
- // 顏色轉換
-
var img = new 新
-
-
img.src = 'images/1.jpg'
'images/1.jpg'-
;
img.onload = 函數
()-
context.drawImage(img, 0,0, 1, 1); -
var imgData = 🎜>
var -
像素 = imgData = imgData =
imgData console.log(像素);
-
for(var i = = 像素.length; i n n n
; -
為中所[i] = 255 - 像素[i]; -
為中所[i 1] = 255 - 像素[i 1]; -
為中所[i 2] = 255 - 像素[i 2]; -
} -
context.putImageData(imgData, 250, 0); -
} -
}