android image gradient
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:
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);
精彩评论