I use ImageIO to obtain a BufferedImage. I then obtain a Graphics object from this BufferedImage. When I try to draw on this Graphics object, the only color that it draws is black. I can setColor() to whatever I want, but the oval or line (i.e.) always draws black. I have toggled between paint & XOR mode without help.
Also, when I BufferedImage.setRGB() for a set of pixels, they always go black regardless of what packed rgb int I give it. I've tried this with both Windows and Linux. What am I missing? I'm a server-side programmer, so must be missing something simple in AWT?
BufferedImage bi = ImageIO.read(
new File("foo.gif") // it's an 800x600 image
);
// do this for any pixel or any color
bi.setRGB(50,50, 255<<16);
java.awt.Graphics g = bi.getGraphics();
g.setPaintMode();
// set the context color to be blue.
g.setColor(java.awt.Color.BLUE);
// are we sure the color is blue?
System.out.println(g.getColor()); // yep
g.drawLine(center_x,max_y,center_x,0);
g.drawLine(0,center_y,max_x,center_y);
// those two lines showed up blac, let's draw a red circle?
g.setColor(java.awt.Color.RED);
g.fillOval(100, 100 , 10,10);
// nope no luck
Any help of course greatly appreciated.