Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Graphics object always drawing black?

843807May 6 2005 — edited May 12 2005
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2005
Added on May 6 2005
1 comment
158 views