Created
September 17, 2015 17:20
-
-
Save mrhether/ee3b87d1bda7c43cf2a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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