Search code examples
androidbitmappolygoncrop

Android Freehand bitmap cropping


I know we can crop a bitmap in rectangular shape using:

Bitmap.createBitmap(source, x, y, width, height)

But I want to know to crop a bitmap in freehand mode or some polygon shape. Its best example can be seen in Jigsaw Puzzle game

I have spent a lot of time googling about this but found no help. Can anybody help me in this regard?


Solution

  • You can use a Path to determine a clip area on your Canvas when drawing a Bitmap.

    For a full example see:

    Android - Crop an image from multipoints

    and also:

    Cutting a multipoint ploygon out of Bitmap and placing it on transparency