I am using the following class to get a rounded ImageView: https://github.com/vinc3m1/RoundedImageView
Everything works fine, however I want to add a shadow and border to my image view like: How to add a shadow and a border on circular imageView android?
I modified the Rounded ImageView class to include these functions :
private void setup()
{
// init paint
paint = new Paint();
paint.setAntiAlias(true);
paintBorder = new Paint();
setBorderColor(Color.WHITE);
paintBorder.setAntiAlias(true);
this.setLayerType(LAYER_TYPE_SOFTWARE, paintBorder);
paintBorder.setShadowLayer(4.0f, 0.0f, 2.0f, Color.BLACK);
}
public Bitmap convertToBitmap(Drawable drawable, int widthPixels, int heightPixels) {
Bitmap mutableBitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mutableBitmap);
drawable.setBounds(0, 0, widthPixels, heightPixels);
drawable.draw(canvas);
return mutableBitmap;
}
@Override
public void onDraw(Canvas canvas)
{
BitmapShader shader = new BitmapShader(Bitmap.createScaledBitmap(convertToBitmap(mDrawable,canvas.getWidth(), canvas.getHeight()), canvas.getWidth(), canvas.getHeight(), false), Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
paint.setShader(shader);
int circleCenter = viewWidth / 2;
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter + borderWidth - 4.0f, paintBorder);
canvas.drawCircle(circleCenter + borderWidth, circleCenter + borderWidth, circleCenter - 4.0f, paint);
}
Now I get the shadow effect, but I dont get the white border. Any hints?