标签:android 图片圆角 porterduffxfermode
/** * 给bitmap画圆角 * * @param bitmap * bitmap对象 * @param roundPX * 圆角的角度 * @return 画好圆角后的bitmap对象 */ public static Bitmap roundBitmap(Bitmap bitmap, float roundPX) { try { final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); Bitmap outputBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(outputBitmap); final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, width, height); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); paint.setFilterBitmap(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(Color.WHITE); canvas.drawRoundRect(rectF, roundPX, roundPX, paint); final PorterDuffXfermode pdx = new PorterDuffXfermode( PorterDuff.Mode.SRC_IN); paint.setXfermode(pdx); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return outputBitmap; } catch (Exception e) { return bitmap; } }
标签:android 图片圆角 porterduffxfermode
原文地址:http://blog.csdn.net/u010142437/article/details/40049497