Created
January 28, 2014 11:26
-
-
Save fada21/8666038 to your computer and use it in GitHub Desktop.
Crops a circle out of the thumbnail photo for Android (by Daniel Olshansky @google )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Bitmap getCroppedBitmap(Bitmap bitmap) { | |
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); | |
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); | |
Canvas canvas = new Canvas(output); | |
final Paint paint = new Paint(); | |
paint.setAntiAlias(true); | |
int halfWidth = bitmap.getWidth() / 2; | |
int halfHeight = bitmap.getHeight() / 2; | |
canvas.drawCircle(halfWidth, halfHeight, Math.max(halfWidth, halfHeight), paint); | |
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); | |
canvas.drawBitmap(bitmap, rect, rect, paint); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment