android开发中圆角图片的绘制

                image1 = (ImageView) findViewById(R.id.image1);
		Drawable drawable = image1.getDrawable();
		Bitmap bitmap = createFramedPhoto(400, 400, drawable, 20);
		image1.setImageBitmap(bitmap);
       /**
	 *
	 * @param x
	 *            图像的宽度
	 * 
	 * @param y
	 *            图像的高度
	 * 
	 * @param imageDrawable
	 *            源图片
	 * 
	 * @param outerRadiusRat
	 *            圆角的大小
	 * @return 圆角图片
	 */
	Bitmap createFramedPhoto(int x, int y, Drawable imageDrawable,
			float outerRadiusRat) {
		// 新建一个新的输出图片
		Bitmap output = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(output);
		// 新建一个矩形
		RectF outerRect = new RectF(0, 0, x, y);
		// 产生一个圆角矩形
		Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
		canvas.drawRoundRect(outerRect, outerRadiusRat, outerRadiusRat, paint);
		// 将源图片绘制到这个圆角矩形上
		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
		imageDrawable.setBounds(0, 0, x, y);
		canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG);
		imageDrawable.draw(canvas);
		canvas.restore();
		return output;
	}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值