给图片切圆角

来源:互联网 发布:电子画册制作软件 编辑:程序博客网 时间:2024/06/06 17:41
/** * 给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;}}

0 0
原创粉丝点击