private Bitmap GetRoundCornerImage(Bitmap bitmap) {
Bitmap oldBitmap = null;
try {
oldBitmap = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
} catch (OutOfMemoryError e) {
while (oldBitmap == null) {
System.gc();
System.runFinalization();
oldBitmap = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
}
}
Canvas canvas = new Canvas(oldBitmap);
Paint paint = new Paint();
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
RectF rectf = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawRoundRect(rectf, bitmap.getWidth() / 5,
bitmap.getHeight() / 5, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, null, rect, paint);
return oldBitmap;
}
转载于:https://my.oschina.net/u/2265966/blog/352897