为图像的圆angular图像android添加边框

我有什么 ::我有一个Imageview,我正在使用picassso作为一个圆圈的图像 在这里输入图像说明

我该怎么做 ::我想添加一个黑色的边框圆形图像使用我当前的实现,如何实现这一点,而不使用第三方库

Picasso.with(this) .load("http://i.imgur.com/DvpvklR.png") .transform(new RoundedTransformation(50, 4)) .resize(100, 100) .centerCrop().into(imageView1); 

RoundedTransformation.java

 // enables hardware accelerated rounded corners // original idea here : http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/ public class RoundedTransformation implements com.squareup.picasso.Transformation { private final int radius; private final int margin; // dp // radius is corner radii in dp // margin is the board in dp public RoundedTransformation(final int radius, final int margin) { this.radius = radius; this.margin = margin; } @Override public Bitmap transform(final Bitmap source) { final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint); if (source != output) { source.recycle(); } return output; } @Override public String key() { return "rounded"; } } 

编辑

 public class RoundedTransformation implements com.squareup.picasso.Transformation { private final int radius; private final int margin; // dp // radius is corner radii in dp // margin is the board in dp public RoundedTransformation(final int radius, final int margin) { this.radius = radius; this.margin = margin; } @Override public Bitmap transform(final Bitmap source) { final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint); if (source != output) { source.recycle(); } Paint paint1 = new Paint(); paint1.setColor(Color.RED); paint1.setStyle(Style.STROKE); paint1.setAntiAlias(true); paint1.setStrokeWidth(2); canvas.drawCircle((source.getWidth() - margin)/2, (source.getHeight() - margin)/2, radius-2, paint1); return output; } @Override public String key() { return "rounded"; } } 

在这里输入图像说明

Solutions Collecting From Web of "为图像的圆angular图像android添加边框"

您可以使用drawCircle和另一个Paint object 。 例如:

 Paint paint = new Paint(); paint.setColor(Color.RED); paint.setStyle(Style.STROKE); paint.setAntiAlias(true); paint.setStrokeWidth(2); canvas.drawCircle((source.getWidth() - margin)/2, (source.getHeight() - margin)/2, radius-2, paint); 

另外,可以使用drawCircle来代替使用drawRoundRect绘制圆

最后的转化课,感谢黑带

 public class RoundedTransformation implements com.squareup.picasso.Transformation { private final int radius; private final int margin; // dp // radius is corner radii in dp // margin is the board in dp public RoundedTransformation(final int radius, final int margin) { this.radius = radius; this.margin = margin; } @Override public Bitmap transform(final Bitmap source) { final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); canvas.drawCircle((source.getWidth() - margin)/2, (source.getHeight() - margin)/2, radius-2, paint); if (source != output) { source.recycle(); } Paint paint1 = new Paint(); paint1.setColor(Color.RED); paint1.setStyle(Style.STROKE); paint1.setAntiAlias(true); paint1.setStrokeWidth(2); canvas.drawCircle((source.getWidth() - margin)/2, (source.getHeight() - margin)/2, radius-2, paint1); return output; } @Override public String key() { return "rounded"; } }