0

I want to add Transparent Rainbow or Spectrum Gradient to Bitmap.

In photoshop it is very easy. Now I want to do it programmatically. I have gone through a lot of research. But gradient has only one starting color and one ending. How could I add the rainbow color(multiple color) Gradient in Android.

Or is there a way to add that effect to bitmap in Android? Like given

enter image description here

Zar E Ahmer
  • 33,936
  • 20
  • 234
  • 300
  • see `LinearGradient (float x0, float y0, float x1, float y1, int[] colors, float[] positions, Shader.TileMode tile)` – pskink Sep 30 '15 at 07:43

1 Answers1

0

for this you can use a translucent image with the desired gradient and put it on top of your image view in a FrameLayout. then capture bitmap of the view.

gradient

once you get your layout ready use this answer to capture bitmap from it

try this to convert a view (framelayout) into a bitmap:

public Bitmap viewToBitmap(View view) {
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);
    return bitmap;
}
Community
  • 1
  • 1
Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78