Created
February 24, 2014 11:26
-
-
Save blaswan/9186725 to your computer and use it in GitHub Desktop.
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 getCircularCroppedBitmap(Bitmap bitmap, int radius) { | |
| Bitmap scaledBitmap; | |
| if (bitmap.getWidth() != radius || bitmap.getHeight() != radius) { | |
| scaledBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false); | |
| } else { | |
| scaledBitmap = bitmap; | |
| } | |
| Bitmap output = Bitmap.createBitmap(scaledBitmap.getWidth(), scaledBitmap.getHeight(), Bitmap.Config.ARGB_8888); | |
| Canvas canvas = new Canvas(output); | |
| final Paint paint = new Paint(); | |
| final Rect rect = new Rect(0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight()); | |
| paint.setAntiAlias(true); | |
| paint.setFilterBitmap(true); | |
| paint.setDither(true); | |
| canvas.drawARGB(0, 0, 0, 0); | |
| paint.setColor(Color.parseColor("#BAB399")); | |
| canvas.drawCircle(scaledBitmap.getWidth() / 2 + 0.7f, scaledBitmap.getHeight() / 2 + 0.7f, scaledBitmap.getWidth() / 2 + 0.1f, paint); | |
| paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); | |
| canvas.drawBitmap(scaledBitmap, rect, rect, paint); | |
| return output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment