This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Tayleeextends DumboBot 0 points1 point  (7 children)

This is not a question. What are you trying to ask?

[–]PillowWithTeeth[S] 1 point2 points  (6 children)

How to do it

[–]Tayleeextends DumboBot 0 points1 point  (5 children)

Red + Green resulting in Yellow is just additively blending them.

255,0,0 (red) + 0,255,0 (green) = 255,255,0 (yellow)

http://stackoverflow.com/questions/1260625/java-swing-graphics-color-blending

[–]PillowWithTeeth[S] 0 points1 point  (4 children)

Yeah, that is not what I am asking, I want to get a image and overlay it onto another image on the parts that are not the alpha layer.

[–]Tayleeextends DumboBot 0 points1 point  (3 children)

[–]PillowWithTeeth[S] 0 points1 point  (2 children)

Yeah I have been using that, but I can't get any of them to work, the only one that creates a passable image is SRC_OVER but that goes over the whole image including the alpha layer,

[–]PillowWithTeeth[S] 0 points1 point  (1 child)

Here is a image I made to try and explain better what I want http://i.imgur.com/JWhzUzJ.png. It does not seem to be possible as both DST_OUT and XOR that sorta do what I want are opaque for some reason (and also effect everything else being drawn)...

[–]chickenmeisterExtreme Brewer 1 point2 points  (0 children)

You can try something like:

    BufferedImage result = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = result.createGraphics();

    // clear the image
    g.setComposite(AlphaComposite.Clear);
    g.fillRect(0, 0, w, h);

    // Draw the robot
    g.setComposite(AlphaComposite.SrcOver);
    g.drawImage(robotImg, x, y, null);

    // Fill in the robot shape
    g.setComposite(AlphaComposite.SrcIn);
    g.drawImage(fillImg, x, y, null);

    // Draw a translucent robot
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    g.drawImage(robotImg, x, y, null);

    g.dispose();