0
@Override protected void onDraw(Canvas canvas) {

        if (mBitmap != null) {

            canvas.drawColor(0xFFAAAAAA);

            canvas.drawBitmap(background,0,0,mBitmapPaint);

            if(isRelevant){
                canvas.drawBitmap(mBitmapLast, 0,0, mBitmapLastPaint);
            }

            canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
                canvas.drawPath(mPath, mPaint);
        }
    }

I've tried switching around the lines

canvas.drawColor(0xFFAAAAAA);
                canvas.drawBitmap(background,0,0,mBitmapPaint);

and when canvas.drawColor(0xFFAAAAAA); is second, my paths will show up when I draw them on the screen. Is there a way to make the background (bitmap) show underneath the canvas paths?

Timothy Miller
  • 291
  • 5
  • 24

1 Answers1

2

Try setting the Xfermode in your Path's paint:

mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));  // or DST_OVER

and see PorterDuff.Mode explained.

Community
  • 1
  • 1
xandy
  • 27,357
  • 8
  • 59
  • 64
  • I guess I just don't understand xfermodes too well... I have two paint variables, one for the current drawings and another for the previous (which is shown in a lighter color, which already uses xfermode.LIGHTEN) how do I go about showing that one? – Timothy Miller Feb 14 '11 at 01:22
  • nvm I solved it, its .LIGHTEN.SRC_OVER I guess a porterduff can have multiples in one paint... – Timothy Miller Feb 14 '11 at 01:26
  • xfermode is an operation applied when you put a pixel on the canvas. It is very useful when you, say, want to do some alpha masking. The problem you have before, is that canvas.drawcolor() is like clear screen (but with a color you preferred) and if you do drawbitmap, it will starts to 'aware' your xfermode. – xandy Feb 14 '11 at 02:02
  • I may have spoken too soon... When I use mPaint.setXfermode(new PorterDuffXferMode(PorterDuff.Mode.LIGHTEN.SRC_OVER); The path shows up, but it is not in a lightened color. Is it possible to show the path over the bitmap in a lightened color? – Timothy Miller Feb 14 '11 at 20:47
  • Lighten? Don't compare porter duff with PS, it's anyway very primitive operation and you really have to figure out how to lighten things. But for instance, you might simply draw a half-transparent white (or any light color) on top of the bitmap. – xandy Feb 15 '11 at 01:41
  • no I wasn't trying to compare porter duff to PS but before I made the background a bitmap, I was able to draw using path and it would show up in a say....pinkish color if the drawn color with a regular porter duff was red. I'll try drawing a half transparent white on top of the bitmap, although I believe that might play bad with the bitmap as it will make that appear brighter due to the drawing routine: background(bitmap), previous path, semi-transparent white over the canvas, and now the current path the user draws. I'll get back to you if this works. – Timothy Miller Feb 21 '11 at 02:16
  • Try experiment the porter duff with various settings. No better fast solution in Android is provided, as far as what I know, unless you go to use NDK to write your native processor. – xandy Feb 21 '11 at 09:26
  • I had better results with `PorterDuff.Mode.SCREEN` – seb Mar 05 '14 at 04:10