public static Bitmap createPillWithShadow(int rectColor, int width, int height) {
float shadowRadius = height * 1f / 32;
float shadowYOffset = height * 1f / 16;
int radius = height / 2;
Canvas canvas = new Canvas();
Paint blurPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
blurPaint.setMaskFilter(new BlurMaskFilter(shadowRadius, Blur.NORMAL));
int centerX = Math.round(width / 2 + shadowRadius);
int centerY = Math.round(radius + shadowRadius + shadowYOffset);
int center = Math.max(centerX, centerY);
int size = center * 2;
Bitmap result = Bitmap.createBitmap(size, size, Config.ARGB_8888);
canvas.setBitmap(result);
int left = center - width / 2;
int top = center - height / 2;
int right = center + width / 2;
int bottom = center + height / 2;
// Draw ambient shadow, center aligned within size
blurPaint.setAlpha(AMBIENT_SHADOW_ALPHA);
canvas.drawRoundRect(left, top, right, bottom, radius, radius, blurPaint);
// Draw key shadow, bottom aligned within size
blurPaint.setAlpha(KEY_SHADOW_ALPHA);
canvas.drawRoundRect(left, top + shadowYOffset, right, bottom + shadowYOffset,
radius, radius, blurPaint);
// Draw the circle
Paint drawPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
drawPaint.setColor(rectColor);
canvas.drawRoundRect(left, top, right, bottom, radius, radius, drawPaint);
return result;
}
ShadowGenerator.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:LaunchEnr
作者:
评论列表
文章目录