イナヅマTVログ

Canvas始めました – 文字を表示

| 0件のコメント

Canvasに文字を描くの巻。

HTML

<canvas id='canvas'></canvas>

JavaScript

var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
 
context.fillStyle = "#000000";
 
context.font = "italic bold 40px serif";
context.textBaseline = "top";
context.fillText('Hello world', 200, 60);

font
文字属性指定, CSS形式で良さげ。

textBaseline
top, hanging, middle, alphabetic, ideographic, bottom

fillText
fillText(text:String, x position:int, y position:int [, max length:int])

コメントを残す

必須欄は * がついています


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください