开发者

android image gradient

开发者 https://www.devze.com 2023-02-15 13:30 出处:网络
I want to create a \"glo开发者_如何学编程w\" effect on top of an image. On dark it\'s almost working, but on bright images you can see a gray rectangle on image, as seen in below image:

I want to create a "glo开发者_如何学编程w" effect on top of an image. On dark it's almost working, but on bright images you can see a gray rectangle on image, as seen in below image:

android image gradient

Here is my code:

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

What am I doing wrong?


I've found the answer. Instead of Color.TRANSPARENT, I've used 0X00FFFFFF:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号