1

I am trying to figure out how to layer two canvases, where one has a bitmap and the second is what I will actually draw on.

So basically what I have is:

    Bitmap newBitmap = Bitmap.createBitmap(img.getWidth(), img.getHeight(),
            Bitmap.Config.RGB_565);
    Canvas newCanvas = new Canvas();
    newCanvas.setBitmap(newBitmap);
    if (img != null) {
        newCanvas.drawBitmap(img, 0, 0, null);
    }
    mBitmap = newBitmap;
    imageCanvas = newCanvas;

    mCanvas = new Canvas();
    drawBitmap = Bitmap.createBitmap(img.getWidth(), img.getHeight(),
            Bitmap.Config.RGB_565);
    mCanvas.setBitmap(drawBitmap);

where mCanvas is what the user will draw on, and imageCanvas is where the bitmap is drawn.

The image is black and white, and I want the black lines to always show through, so I want it as the top of the stack.

It seems I will need to ensure that the white parts of the image need to be transparent, which I may need to do when I load the image, as expecting it to be like this is too much to expect.

So, how do I stack these two canvases in the same view and have where the drawLine shows up on the bottom canvas?

I did look at this question, but I don't think it is similar:

layered images plus canvas

Community
  • 1
  • 1
James Black
  • 41,583
  • 10
  • 86
  • 166

1 Answers1

0

The solution was simpler than I expected.

I have a menu option to allow users to draw a transparent image, so that only the black lines for the image are visible, the rest of the image is transparent.

By doing this, then I could just draw the bitmap the user is drawing on, first, then draw the image with mostly transparent colors.

This makes the black lines always visible.

I may need to use a PorterDuff xfer mode to make it look better, but this meets my initial requirements.

I was surprised that having the drawable image be on the background didn't work.

I am doing all of this in a custom View.

James Black
  • 41,583
  • 10
  • 86
  • 166