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?

canvas.width に同じ値を入れても描画状態はリセットされる

0
Posted at

canvas.width に現在と同じ値を代入しても、描画バッファとコンテキストの状態はリセットされる。幅を揃えるための代入でも、すでに描いた内容は消える。

サイズを決めてから fillStyle や変換を設定する。幅への代入で、それらも初期状態へ戻るためだ。CSS の表示幅を変える操作とは区別する。

同じ値なら代入を省く設計にする場合、リセット自体を目的にしている処理まで省かないように確認する。消去だけが必要なら、その目的に合う描画操作を選ぶ。

参考: MDN HTMLCanvasElement.width

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?