Search code examples
androidpathbitmapcliprect

Create several bitmaps from a large bitmap using paths or rects


So I have a bitmap.. Now I want to create 5 smaller bitmaps from specific regions of the original bitmap.

Is it possible to do this with paths or rects?

for instance : newBitmap = OriginalBitmap.copyFromArea(Path data | rect)


Solution

  • You can use the createBitmap static method form the Bitmap class.

    For example, if you have a 20x25 image (originalBitmap) and want a 5x6 slice (newSlice) at the bottom right corner, then you can do the following:

    Bitmap newSlice = Bitmap.createBitmap (originalBitmap, 15, 19, 5, 6);