Skip to content

Instantly share code, notes, and snippets.

@mrhether
Created September 17, 2015 17:20
Show Gist options
  • Save mrhether/ee3b87d1bda7c43cf2a8 to your computer and use it in GitHub Desktop.
Save mrhether/ee3b87d1bda7c43cf2a8 to your computer and use it in GitHub Desktop.
public static Bitmap addGradient(Bitmap src, @ColorInt int start, @ColorInt int end, int alpha) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap overlay = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, 0, 0, h, start, end, Shader.TileMode.CLAMP);
paint.setShader(shader);
paint.setStyle(Paint.Style.FILL);
paint.setAlpha(alpha);
canvas.drawRect(0, 0, w, h, paint);
return overlay;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment