HTML 캔버스 strokeText() 메서드

❮ HTML 캔버스 참조

예시

"Hello world!"라고 쓰세요. 그리고 "큰 미소!" (그라디언트 포함) strokeText()를 사용하여 캔버스에서:

브라우저는 HTML5캔버스태그를 지원하지 않습니다.

자바스크립트:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

ctx.font = "20px Georgia";
ctx.strokeText("Hello World!", 10, 50);

ctx.font = "30px Verdana";
// Create gradient

var gradient = ctx.createLinearGradient(0, 0, c.width, 0);
gradient.addColorStop("0", "magenta");
gradient.addColorStop("0.5", "blue");
gradient.addColorStop("1.0", "red");

// Fill with gradient
ctx.strokeStyle = gradient;
ctx.strokeText("Big smile!", 10, 90);

브라우저 지원

표의 숫자는 이 방법을 완전히 지원하는 첫 번째 브라우저 버전을 지정합니다.

Method
strokeText() Yes 9.0 Yes Yes Yes

참고: maxWidth 매개변수는 Safari 5.1 및 이전 버전에서 지원되지 않습니다.


정의 및 사용

strokeText() 메서드는 캔버스에 텍스트(채우기 없음)를 그립니다. 텍스트의 기본 색상은 검정색입니다.

팁: font 속성을 사용하여 글꼴 및 글꼴 크기를 지정하고 strokeStyle 속성을 사용하여 다른 색상/그라데이션으로 텍스트를 렌더링합니다.

자바스크립트 구문: 컨텍스트 .strokeText( 텍스트,x,y, 최대폭 );

매개변수 값

Parameter Description Play it
text Specifies the text that will be written on the canvas
x The x coordinate where to start painting the text (relative to the canvas)
y The y coordinate where to start painting the text (relative to the canvas)
maxWidth Optional. The maximum allowed width of the text, in pixels

❮ HTML 캔버스 참조