Android canvas - Draw a hole -
is possible realize following picture in android canvas?
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
Post a Comment