transparent colors and setXORMode doesn't work together
- From: Zaka Ferenc <zakaf@xxxxxxxxxxx>
- Date: Thu, 24 Aug 2006 17:57:41 +0200
Hello,
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.
Thanks,
Feri
.
- Follow-Ups:
- Re: transparent colors and setXORMode doesn't work together
- From: Andrey Kuznetsov
- Re: transparent colors and setXORMode doesn't work together
- Prev by Date: Re: Java GUI(Swing) VS Windows forms in VB6/VB.NET
- Next by Date: Rendering CAD/GIS Data on a Map Canvas
- Previous by thread: Window freezes when pressed CTRL + P
- Next by thread: Re: transparent colors and setXORMode doesn't work together
- Index(es):