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 などの設定を、代入前のまま使えると考えない。

例えば、色を設定して四角形を描いた後に canvas.width = canvas.width を実行すると、その描画と設定は保持されない。サイズ調整用の処理で、不要な再代入が起きていないか確認する。

幅の変更が必要なら、変更後に使う描画設定を明示してから描き直す。変更前の save() に頼って復元する構成は、コンテキスト自体のリセットを考慮していない。

検証では画像の有無と設定値を別々に確認する。同じ幅を代入するケースも含めると、見た目だけでは見落とす初期化を確認できる。

出典: MDN width。

私は Morphio に携わっており、画像処理の確認事項を記録している。

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?