1

我正在尝试使用下面的代码来圆位图的角落。问题是,无论我将油漆的颜色设置为什么,例如Color.TRANSPARENT,它始终是黑色的。我如何才能实际剪辑位图的角,而不仅仅是将它们涂成黑色?

谢谢!

    public static Bitmap roundCorners(Bitmap src, int radius) {
    //Create a *mutable* location, and a canvas to draw into it
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    RectF rect = new RectF(0, 0, width, height);
    Shader bitmapShader = new BitmapShader(src, TileMode.CLAMP, TileMode.CLAMP);
    paint.setColor(0xFF000000);
    paint.setShader(bitmapShader);
    canvas.drawRoundRect(rect, radius, radius, paint);
    return result;
}
4

1 回答 1

4

有一种更简单的方法可以一次性使用。只需绘制一个圆角矩形,但在 Paint 上设置一个 BitmapShader。这将用您的位图填充圆角矩形。无需更改 xfermode 或调用 drawBitmap。

于 2012-11-27T17:30:07.213 回答