42
44

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Canvasを透明色で塗りつぶす

Posted at

SurfaceView上で描画をするには、Canvasを使用することが多いと思うけど、
Canvasをクリアしたい時の方法。

例として、透明色でクリアする場合。

SubSurfaceView.java
Canvas canvas = getHolder().lockCanvas();
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
// 描画処理...
getHolder().unlockCanvasAndPost(canvas);

drawColor(Color.TRANSPARENT)とやってもダメ。
第二引数を省略すると、drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC_OVER);に置き換えられて実行されてしまう。
(※ソース:リファレンス

ちなみに、PorterDuffの各モードの意味は、下記サイトが参考になる。
Merlinの魔術: Porter-Duffのルール

42
44
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
42
44

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?