Skip to content

Instantly share code, notes, and snippets.

@jrgcubano
Forked from davidtavarez/getCropBitmap
Created August 29, 2016 13:52
Show Gist options
  • Save jrgcubano/46b08d8e6bdf6fa128c3f82271c3a3f6 to your computer and use it in GitHub Desktop.
Save jrgcubano/46b08d8e6bdf6fa128c3f82271c3a3f6 to your computer and use it in GitHub Desktop.
private static Bitmap getCropBitmap (Bitmap origialBitmap,int left, int top, int right, int bottom){
int targetWidth = right-left;
int targetHeight = bottom-top;
Bitmap cutBitmap = Bitmap.createBitmap(targetWidth,targetHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(cutBitmap);
Rect desRect = new Rect(0, 0, targetWidth, targetHeight);
Rect srcRect = new Rect(left, top, right, bottom);
canvas.drawBitmap(origialBitmap, srcRect, desRect, null);
return cutBitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment