/** * 根据原图和变长绘制圆形图片 * * @param source * @param min * @return */ public static Bitmap createCircleImage(Bitmap source, int min) { Paint paint = new Paint(); // paint.setStyle(Paint.Style.STROKE); // paint.setFlags(Paint.ANTI_ALIAS_FLAG); paint.setAntiAlias(true); paint.setFilterBitmap(true); Bitmap target = Bitmap.createBitmap(min, min, source.getConfig()); /** * 产生一个同样大小的画布 */ Canvas canvas = new Canvas(target); /** * 首先绘制圆形 */ canvas.drawCircle(min / 2, min / 2, min / 2, paint); /** * 使用SRC_IN */ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); /** * 给Canvas加上抗锯齿标志 */ canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG)); /** * 绘制图片 */ canvas.drawBitmap(source, 0, 0, paint); return target; }
本文转自秋楓博客园博客,原文链接:http://www.cnblogs.com/rwxwsblog/p/5694503.html,如需转载请自行联系原作者