Android canvas - Draw a hole -


is possible realize following picture in android canvas?

picture hole

i want have hole , not circle on red layer yellow colored. tried (and failed) following code in ondraw()-method:

canvas.drawbitmap(yellow, 0, 0, paint); canvas.drawbitmap(red, 0, 200, paint); paint p = new paint(); p.setxfermode(new porterduffxfermode(porterduff.mode.clear)); canvas.drawcircle(300, 300, radius, p); 

but when use code, makes hole through both bitmap's. @ end, app should maze ball, holes , other stuff. when ball fall hole should appear under red-bitmap. possible realize this?

answer:

if should have same problem: use view , not surfaceview. fault, because bg of surfaceview not set transparent.

i think you're misunderstanding how canvas/bitmaps work. there aren't layers or objects stored (unless store them). it's pixel pixel representation of image displayed. yellow circle on red square is have shown in above picture.

if want red layer, have composite 2 bitmaps. draw hole on red square in 1 bitmap, draw yellow layer in 1 bitmap. on canvas, draw yellow bitmap, "red square hole" bitmap on top.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -