0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Canvas 繪圖 - 基本教學 By 彭彭

Posted at

JavaScript 進階功能
/* Canvas 繪圖

  • a. 基本教學
  • b. 影像處理
  • c. 檔案的輸入與輸出
    */

a. 基本教學

qiita.rb

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Canvas 繪圖</title>
<script type="text/javascript">
window.onload=function(){
	var cvs = document.getElementById("cvs");
	var ctx = cvs.getContext("2d"); //2d繪圖 Canvas Context Object
	// Fill 填滿
	ctx.fillStyle = "pink";
	ctx.globalAlpha = 0.9;
	ctx.fillRect(50, 50, 100, 100);
	// Stroke 描邊
	ctx.globalAlpha = 1;
	ctx.strokeStyle = "dark gray";
	ctx.strokeRect(200, 100, 200, 200);
	// Path 路徑
	ctx.beginPath(); //開始建立路徑
	ctx.moveTo(200, 50); // 移動當前所在位置
	ctx.lineTo(400, 50);
	ctx.closePath();
	ctx.stroke(); // ctx.fill(); 描邊or填色
	// 利用路徑畫出多邊形
	ctx.beginPath();
	ctx.moveTo(200, 200);
	ctx.lineTo(300, 200);
	ctx.lineTo(300, 300);
	ctx.closePath();
	ctx.stroke();
	ctx.fill(); // ctx.fill(); 描邊or填色
};
</script>
</head>
<body>
<canvas id="cvs" width="600" height="500" style="border:1px solid #000000"></canvas>
</body>
</html>

b. 影像處理

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?