0

I have bitmap on which I am applying two masks. When I apply mask on the right side of bitmap, it works fine but after that when I apply mask on the bottom side of the same bitmap, I have an area on bitmap that reappear again due to remasking. I have tried to explain this issue using pic below. The area circled is causing problem. I want that area remains transparent even after remasking.

enter image description here

Here are my masking functions code snipped.

paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
.......

public void setRightMask(MyBitmap bmp, Type type) {
    int maskIndex = -1;
    switch(type){
        case CONCAVE:
            maskIndex = 0;
            break;
        case CONVEX:
            maskIndex = 6;
            break;

    }

    Bitmap result = Bitmap.createBitmap((int)bmp.getWidth(), (int)bmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(bmp.getBmp(), 0, 0, null);
    canvas.drawBitmap(masks[maskIndex].getBmp(), bmp.getWidth() - masks[maskIndex].getBmp().getWidth(), 0, paint);
    bmp.setBmp(result);
}


public void setBottomMask(MyBitmap bmp, Type type) {
    int maskIndex = -1;
    switch(type){
        case CONCAVE:
            maskIndex = 1;
            break;
        case CONVEX:
            maskIndex = 7;
            break;

    }

    Bitmap result = Bitmap.createBitmap((int)bmp.getWidth(), (int)bmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(bmp.getBmp(), 0, 0, null);
    canvas.drawBitmap(masks[maskIndex].getBmp(), 0, bmp.getHeight() - masks[maskIndex].getBmp().getHeight(), paint);
    bmp.setBmp(result);
}
Khawar Raza
  • 15,870
  • 24
  • 70
  • 127

1 Answers1

0

One solution could be to use black-transparent masks instead of black-white. Though whith the black-transparent mask you first have to draw the masks and then draw whatever you want to be cropped by those masks with

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

instead of Mode.DST_IN.

croc
  • 1,416
  • 1
  • 18
  • 24