android图像渐变

时间:2011-03-09 08:45:19

标签: android gradient image

我想在图像上创建“发光”效果。在黑暗中,它几乎正常工作,但在明亮的图像上,您可以在图像上看到灰色矩形,如下图所示:

image gradient effect

这是我的代码:

    public static Bitmap drawModifiedImage(Bitmap bitmap) {
    Canvas bigCanvas = new Canvas(bitmap);
    Bitmap b = Bitmap.createBitmap(bitmap.getWidth(), 20, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(b);
    c.drawColor(Color.TRANSPARENT);
    LinearGradient grad = new LinearGradient(bitmap.getWidth()/2, 0, bitmap.getWidth()/2, 20, Color.WHITE, Color.TRANSPARENT, Shader.TileMode.CLAMP);
    Paint p = new Paint();
    p.setStyle(Paint.Style.FILL);
    p.setShader(grad);
    c.drawRect(0, 0, bitmap.getWidth(), 20, p);
    bigCanvas.drawBitmap(bitmap, 0, 0, null);
    bigCanvas.drawBitmap(b,0,0, null);
    return bitmap;
}

我做错了什么?

1 个答案:

答案 0 :(得分:2)

我找到了答案。我没有使用Color.TRANSPARENT,而是使用了0X00FFFFFF:

LinearGradient grad = new LinearGradient(bitmap.getWidth()/2, 0, bitmap.getWidth()/2, 20, Color.WHITE, 0X00FFFFFF, Shader.TileMode.CLAMP);