package com.wenyu.Utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;

public class RoundedCornerImageView extends ImageView {

	private final float density = getContext().getResources()
			.getDisplayMetrics().density;
	private float roundness;

	public RoundedCornerImageView(Context context) {
		super(context);

		init();
	}

	public RoundedCornerImageView(Context context, AttributeSet attrs) {
		super(context, attrs);

		init();
	}

	public RoundedCornerImageView(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);

		init();
	}

	@Override
	public void draw(Canvas canvas) {
		final Bitmap composedBitmap;
		final Bitmap originalBitmap;
		final Canvas composedCanvas;
		final Canvas originalCanvas;
		final Paint paint;
		final int height;
		final int width;

		width = getWidth();

		height = getHeight();

		composedBitmap = Bitmap.createBitmap(width, height,
				Bitmap.Config.ARGB_8888);
		originalBitmap = Bitmap.createBitmap(width, height,
				Bitmap.Config.ARGB_8888);

		composedCanvas = new Canvas(composedBitmap);
		originalCanvas = new Canvas(originalBitmap);

		paint = new Paint();
		paint.setAntiAlias(true);
		paint.setColor(Color.BLACK);

		super.draw(originalCanvas);

		composedCanvas.drawARGB(0, 0, 0, 0);

		composedCanvas.drawRoundRect(new RectF(0, 0, width, height),
				this.roundness, this.roundness, paint);

		paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));

		composedCanvas.drawBitmap(originalBitmap, 0, 0, paint);

		canvas.drawBitmap(composedBitmap, 0, 0, new Paint());
	}

	public float getRoundness() {
		return this.roundness / this.density;
	}

	public void setRoundness(float roundness) {
		this.roundness = roundness * this.density;
	}

	private void init() {
		//括号中的数字是调整图片弧度的  调成100为圆形图? 调成15为圆角图?
		setRoundness(100);
	}
}

@@ -177,16 +177,53 @@
 .Paint;%0A
+import android.graphics.Paint.Style;%0A
 import a
@@ -1646,27 +1646,29 @@
 ctF(
-0, 0
+5, 5
 , width
+-5
 , height
 ),%0A%09
@@ -1663,16 +1663,18 @@
 , height
+-5
 ),%0A%09%09%09%09t
@@ -1712,17 +1712,16 @@
 paint);%0A
-%0A
 %09%09paint.
@@ -1770,17 +1770,16 @@
 C_IN));%0A
-%0A
 %09%09compos
@@ -1828,16 +1828,292 @@
 paint);%0A
+%09%09Paint temppaint = new Paint();%0A%09%09temppaint.setStyle(Style.STROKE);%0A%09%09temppaint.setStrokeWidth(2);%0A%09%09temppaint.setColor(Color.BLACK);%0A%09%09int circle = width %3C height ? width : height;%0A%09%09circle = circle / 2;%0A%09%09composedCanvas.drawCircle(width/2, height/2, circle - 3, temppaint);
 %0A%09%09canva

add edging for round pic