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?

clip() の解除には保存した描画状態へ戻す

0
Posted at

clip() を一時的に使うなら、その前に描画状態を保存する。新しいクリップは現在の領域と交差するので、以前の範囲へ戻すには保存した状態を restore() する。

例えば、save()、beginPath()、rect()、clip()、描画、restore() の順にする。rect() はパスを作る。fillRect() は直接描画するので、その呼び出しだけではクリップ用のパスを追加しない。

restore() の後に別の場所へ目印を描き、クリップが残っていないことを確認する。保存より前から存在したクリップは復元先にも含まれるので、どの状態を保存したかも確認が必要になる。

描画関数の呼び出し側と保存の担当を決め、対応する restore() を省かない。例外が起こる処理を挟むなら、finally で復元する構成も検討できる。

出典: MDN clip()。

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?