Re: transparent colors and setXORMode doesn't work together



I would like to draw multiple partially overlapping figures in xor mode
(applying the even-odd rule) and then place the drawing on another image.

I've tried this on a JPanel:

public void paintComponent(Graphics g) {
super.paintComponent( g );
Graphics2D g2 = (Graphics2D) g;

Dimension d = getSize();
int w = d.width;
int h = d.height;

BufferedImage buffImg = new BufferedImage(w, h,
BufferedImage.TYPE_INT_ARGB);
Graphics2D gbi = buffImg.createGraphics();

gbi.setColor(new Color(1f,1f,1f,0f)); // I except that it clears
the Graphics with "white" transparent color
gbi.fillRect(0, 0, d.width, d.height);

gbi.setXORMode(new Color(0f,0f,1f, 1f)); // it would be tell
Graphics to alternate opaque blue and transparent white

int rectx = w/4; // draw the two partially overlapping figure
int recty = h/4;
gbi.fill(new Rectangle2D.Double(rectx, recty, 150, 100));
gbi.fill(new
Ellipse2D.Double(rectx+rectx/2,recty+recty/2,150,100));


g2.setColor(Color.green);
g2.fillRect(30,30, 100, 140); // it shows what happens with the
previously drawed things

g2.drawImage(buffImg, null, 0, 0);
}


It draws only the green rectangle, ie. the BufferedImage contains
tansparency only. :(
If I change the clearing transparent white to this way
gbi.setColor(new Color(1f,1f,1f,1f)); // opaque white
then the blue figures shows correctly, but the green rectangle goes away
because of no transparency.

What did I wrong?

Any working solution/idea would be greatly appreciated.

fill these 2 rectangles with opaque white first.

Andrey

--
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities


.