Created
July 22, 2013 03:26
-
-
Save eveliotc/6051122 to your computer and use it in GitHub Desktop.
A better yet dirty way of get rounded avatars
This file contains hidden or 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 static Bitmap getRoundedBitmap(Bitmap bitmap) { | |
final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); | |
final Canvas canvas = new Canvas(output); | |
final int color = Color.RED; | |
final Paint paint = new Paint(); | |
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); | |
final RectF rectF = new RectF(rect); | |
paint.setAntiAlias(true); | |
canvas.drawARGB(0, 0, 0, 0); | |
paint.setColor(color); | |
canvas.drawOval(rectF, paint); | |
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); | |
canvas.drawBitmap(bitmap, rect, rect, paint); | |
bitmap.recycle(); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment