Android在带圆角的位图上留下阴影

时间:2013-06-08 17:18:54

标签: java android bitmap

所以我目前正在使用此代码制作圆形位图:

public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
        bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xff424242;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = 36;

    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);

    return output;
  }

我想在圆圈的边缘添加阴影,我该怎么做?

谢谢,斯威夫特

1 个答案:

答案 0 :(得分:0)

您只需使用Paint方法即可使用setShadowLayer方法添加阴影

像这样使用您当前的绘画对象

paint.setShadowLayer(10f, 0f, 0f, Color.DKGRAY)