Cut region out of Bitmap with Path

1k views Asked by At

I'm trying to get cut a jigsaw puzzle piece out of an image, creating a new Bitmap image. I'm using a Path object to do this. This is the current result.

enter image description here

And how I achived this

    Path path = new Path();
    // Multiple path methods to create shape of puzzle piece...
    path.close();

    Bitmap source = BitmapFactory.decodeResource(getResources(), R.drawable.flowers);
    Bitmap workingCopy = source.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(workingCopy);
    path.setFillType(Path.FillType.INVERSE_WINDING);
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    canvas.drawPath(path, paint);

    ((ImageView) findViewById(R.id.myImage)).setImageBitmap(workingCopy);

I wish I could have it transparent instead of black and cut out everything outside the bounds of path.

1

There are 1 answers

0
Stefaan Neyts On

I've tried it using a PNG-file with transparancy, and the background is transparent in stead of black.