当前位置: 代码迷 >> Android >> Android 图片圆角处置
  详细解决方案

Android 图片圆角处置

热度:42   发布时间:2016-05-01 11:47:41.0
Android 图片圆角处理

绘制图形时,通过绘制相交的部分来实现,不多说,看代码:

	public static Bitmap getRoundedCornerBitmap(Bitmap sourceBitmap, float roundX, float roundY) {				try {						Bitmap targetBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(), Config.ARGB_8888);			Canvas canvas = new Canvas(targetBitmap);			Paint paint = new Paint();			Rect rect = new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight());			RectF rectF = new RectF(rect);			paint.setAntiAlias(true);			canvas.drawARGB(0, 0, 0, 0);			canvas.drawRoundRect(rectF, roundX, roundY, paint);			paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));			canvas.drawBitmap(sourceBitmap, rect, rect, paint);			return targetBitmap;					} catch (Exception e) {			e.printStackTrace();		}				return null;			}

?效果图:



?

?

?

?

  相关解决方案