I have done some extensive searching for code examples on this but cannot find anything.
In particular, I am looking to add a shadow to a png drawable I am using in
This helped me to get the shadow working so I wanted to share the working code:
private Bitmap createShadowBitmap(Bitmap originalBitmap) {
BlurMaskFilter blurFilter = new BlurMaskFilter(5, BlurMaskFilter.Blur.OUTER);
Paint shadowPaint = new Paint();
shadowPaint.setMaskFilter(blurFilter);
int[] offsetXY = new int[2];
Bitmap shadowImage = originalBitmap.extractAlpha(shadowPaint, offsetXY);
/* Need to convert shadowImage from 8-bit to ARGB here. */
Bitmap shadowImage32 = shadowImage.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(shadowImage32);
c.drawBitmap(originalBitmap, -offsetXY[0], -offsetXY[1], null);
return shadowImage32;
}