码迷,mamicode.com
首页 > 其他好文 > 详细

给图片切圆角

时间:2014-10-13 21:04:57      阅读:172      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!