Drawing on Canvas - PorterDuff.Mode.CLEAR draws black! Why? Drawing on Canvas - PorterDuff.Mode.CLEAR draws black! Why? android android

Drawing on Canvas - PorterDuff.Mode.CLEAR draws black! Why?


PorterDuff.Mode.CLEAR doesn't work with hardware acceleration. Just set

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

Works perfectly for me.


Use this statement during initialization of the view

setLayerType(LAYER_TYPE_HARDWARE, null);


Everything is ok in your code except one thing: you get black background because your window is opaque. To achieve transparent result you should draw on another bitmap. In your onDraw method please a create new bitmap and do all the staff on it. After that draw this bitmap on your canvas.

For details and sample code please read this my answer: