Created
January 25, 2013 08:03
-
-
Save sermojohn/4632652 to your computer and use it in GitHub Desktop.
Utility method for generating an image with rounded corners from an image with proper corners.
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 class ImageUtils { | |
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int radius, int bgcolor) { | |
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); | |
Canvas canvas = new Canvas(output); | |
final Paint paint = new Paint(); | |
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); | |
final RectF rectF = new RectF(rect); | |
final float roundPx = radius; | |
paint.setAntiAlias(true); | |
canvas.drawARGB(0, 0, 0, 0); | |
paint.setColor(bgcolor); | |
canvas.drawRoundRect(rectF, roundPx, roundPx, paint); | |
paint.setXfermode(new PorterDuffXfermode(PorterDuff.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