Reputation: 1223
Just for learning purposes, I want to know how the shadow image is created in the nova launcher when we drag the application icon on the grid, I had searched in Google for whole day but I am not able to find any suggestions, so if you guys know how it is drawn it will be more helpful.
Thanks in advance.
Edit: After doing bit learning was able to achieve with below code.
public static Bitmap getShadowBitmap(Bitmap src) {
Bitmap bmOut = Bitmap.createBitmap(src.getWidth(),
src.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmOut);
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
Paint ptBlur = new Paint();
ptBlur.setMaskFilter(new BlurMaskFilter(5, BlurMaskFilter.Blur.NORMAL));
int[] offsetXY = new int[2];
Bitmap bmAlpha = src.extractAlpha(ptBlur, offsetXY);
Paint ptAlphaColor = new Paint();
ptAlphaColor.setColor(Color.WHITE);
canvas.drawBitmap(bmAlpha, offsetXY[0], offsetXY[1], ptAlphaColor);
bmAlpha.recycle();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
paint.setColor(Color.TRANSPARENT);
paint.setAlpha(0);
canvas.drawBitmap(src, 0, 0, paint);
return bmOut;
}
Upvotes: 1
Views: 3436
Reputation: 3903
You can use canvas to get the boundary of an image icon and can create an outline of your desired color using path on canvas or you can use some library like bellow to get some idea of how it's working.
https://github.com/DevLight-Mobile-Agency/ShadowLayout
Upvotes: 1