java - How to draw a gradient with opacity -


i have method, makes gradient, reason can not make gradient have opacity, such 60% opaque.

public static int[] linear(int x1, int y1, int x2, int y2, color color1, color color2, int width, int height){     bufferedimage bimg = new bufferedimage(width, height, bufferedimage.type_int_argb);     int[] pixels = new int[width * height];     graphics2d g = bimg.creategraphics();     g.setpaint(new gradientpaint(x1, y1, color1, x2, y2, color2, false));     g.fillrect(0, 0, width, height);     bimg.getrgb(0, 0, width, height, pixels, 0, width);     return pixels;  } 

i call this:

int pink = colors.rgba(187, 61, 186, 153); int yellow = colors.rgba(209, 192, 8, 153); this.spixels = gradient.linear(0, 0, img.getwidth(), 0, pink, yellow, img.getwidth(), img.getheight()); 

i can not life of me gradient 60% opaque. can make that?

here more background:

i have image, create gradient size of image (with above code). next blend 2 images using lighten:

public static int lighten(int bg, int fg){     color bgc = new color(bg);     color fgc = new color(fg);     int r = math.max(bgc.getred(), fgc.getred());     int g = math.max(bgc.getgreen(), fgc.getgreen());     int b = math.max(bgc.getblue(), fgc.getblue());     int = math.max(bgc.gettransparency(), fgc.gettransparency());     color f = new color(r, g, b, a);     return f.getrgb(); } 

no matter how transparent make gradient, lighten doesn't seem catch it, , blends full color, , ignores transparency of gradient.

definen composite object this

private static composite comp = alphacomposite.getinstance(alphacomposite.src_over, 0.6f); 

in linear() method, set composite before g.fillrect()

the following code snippet, demonstrates thing in painting method of 1 of codes...

        gg.setcomposite(comp);         color ec = gg.getcolor();          gg.setcolor(color.darkgray);          shape s = gg.getclip();         if (s != null)             gg.fill(s);          gg.setcomposite(existing);         gg.setcolor(ec); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -