Created
August 19, 2016 06:42
-
-
Save JonghyuKim/43f66fe016306ebb1fef464386b74b46 to your computer and use it in GitHub Desktop.
circleBitmap
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 Bitmap getCircleBitmap(Bitmap bitmap, int strockWidth, int circleColor) { | |
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); | |
Canvas canvas = new Canvas(output); | |
Paint paint = new Paint(); | |
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); | |
paint.setAntiAlias(true); | |
canvas.drawARGB(0, 0, 0, 0); | |
paint.setColor(0xFFFFFFFF); | |
int size = (bitmap.getWidth()/2); | |
canvas.drawCircle(size, size, size, paint); | |
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); | |
canvas.drawBitmap(bitmap, rect, rect, paint); | |
if(strockWidth > 0){ | |
paint = new Paint(); | |
paint.setDither(true); | |
paint.setColor(circleColor); | |
paint.setStyle(Paint.Style.STROKE); | |
paint.setAntiAlias(true); | |
paint.setStrokeWidth(strockWidth); | |
canvas.drawCircle(size, size, size, paint); | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment