Skip to content

Instantly share code, notes, and snippets.

@leelei
Last active August 29, 2015 14:08
Show Gist options
  • Save leelei/41ad02cdab9ab4c001aa to your computer and use it in GitHub Desktop.
Save leelei/41ad02cdab9ab4c001aa to your computer and use it in GitHub Desktop.
BitmapRoundedTransformation
public Bitmap transform(final Bitmap source) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
Bitmap output = Bitmap.createBitmap(source.getWidth(),
source.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawRoundRect(new RectF(margin, margin,
source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);
if (source != output) {
source.recycle();
}
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment