The source Bitmap must be properly prepared, i.e. filtered and scaled with, for example, appropriate density, etc. Then you must define a rectangle that captures one piece. Say:
int desiredX0Lcl=50, desiredY0Lcl=70, desiredX1Lcl=400, desiredY1Lcl=500; Rect sourceRectLcl= new Rect(); sourceRectLcl.set(desiredX0Lcl,desiredY0Lcl,desiredX1Lcl,desiredY1Lcl);
Now create a destination rectangle with borders corresponding to the desired part of sourceBitmap:
Rect destinationRectLcl=new Rect(); int widthLcl=desiredX1Lcl-desiredX0Lcl; int heightLcl=desiredY1Lcl-desiredY0Lcl; destinationRectLcl.set(0,0,widthLcl,heightLcl);
create destinationCanvas:
Bitmap baseCanvasBitmapLcl = Bitmap.createBitmap(widthLcl,heightLcl ,Bitmap.Config.ARGB_8888); Canvas destCanvasLcl = new Canvas(baseCanvasBitmapLcl);
And draw the desired part of sourceBitmap:
destCanvasLcl.drawBitmap(sourceBitmap,sourceRectLcl,destinationRectLcl,null); //sourceBitmap.recycle;
source share