canvas 에 텍스트 그리기
html)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, height=device-height, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0"> <title>Insert title here</title> <script type="text/javascript"> window.onload = function(){ var canvas = document.getElementById("canvas"); if(canvas.getContext){ var draw = canvas.getContext("2d"); //font = "스타일 폰트크기 폰트" draw.font = "bold 40px sans-serif"; //fillStyle : 텍스트 배경색 draw.fillStyle = "green"; //fillText(텍스트, 기준점x, 기준점y) : 채워진 텍스트 draw.fillText("Hello Canvas", 5,50); //strokeStyle : 텍스트 선색 draw.strokeStyle = "blue"; //lineWidth : 선 굵기 draw.lineWidth = 2; //textAlign : 가로정렬 (left, center, right) //textBaseline : 세로정렬 (top, middle, bottom) draw.textAlign = "center"; //strokeText(텍스트, 기준점x, 기준점y) : 선 텍스트 draw.strokeText("Hello Canvas", 5,100); } } </script> </head> <body> <canvas id="canvas" width="300px" height="400px"></canvas> </body> </html> | cs |
결과
'IT > - 프로그래밍' 카테고리의 다른 글
HTML5/CSS3 canvas 도형의 이동, 회전, 확대 (0) | 2017.07.14 |
---|---|
HTML5/CSS3 canvas의 save, restore : 설정 저장,복구 (0) | 2017.07.13 |
HTML5/CSS3 canvas 에 이미지 띄우기 (0) | 2017.07.11 |
HTML5/CSS3 canvas 에 그라디언트 적용하기 (0) | 2017.07.10 |
HTML5/CSS3 canvas 의 clearRect : 해당하는 영역만큼 지운다 (0) | 2017.07.09 |