I am setting rounded image in imageView. Now, I want to set border for rounded image view.
If it is simple rectangle image then we can do it by setting background color for that image view and setting padding. So it will look like it has a border.
But How I can set border for rounded image view ?
My code to create rounded image for square
public static Bitmap getRoundededImage(Bitmap bitmap, int diameter) {
Bitmap output = null;
try {
output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),
Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
int rectX = (bitmap.getWidth() - diameter) / 2;
int rectY = (bitmap.getHeight() - diameter) / 2;
final Rect rect = new Rect(rectX, rectY, rectX + diameter, rectY
+ diameter);
final RectF rectF = new RectF(rect);
final float roundPx = diameter;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
// draw border
paint.setColor(color);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth((float) 20);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
return output;
}
I tried to search and found this Question. I tried this solution but it didn't work. When I applied this solution nothing changed in image.
Please help me to resolve this or guide me in a right path.