FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Java BufferedImage, is it always black?





tekanubis
I'm trying to get my buffered Image to turn white, but the only solution I've found is to just fill a big rectangle over the entire thing, then draw on it. Just curious if anyone had a better idea.

This is more or less how I'm doing it. There's more code, but I cut it off since it's not necessary


Code:
Graph()throws IOException
        {
            // Create a frame
            JFrame frame = new JFrame();

            // Add a component with a custom paint method
            frame.getContentPane().add(new MyComponent());


            // Display the frame
            int frameWidth = 860;
            int frameHeight = 1090;
            frame.setSize(frameWidth, frameHeight);
            frame.setVisible(true);
            frame.setBackground( Color.WHITE );
            // Exit program on closing
            frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {System.exit(0);}
            });
         
        }
   
        class MyComponent extends JComponent
        {
            public void paint(Graphics g)
            {
               g.setColor(Color.WHITE);
               BufferedImage image =
                    new BufferedImage(860, 1090, BufferedImage.TYPE_INT_BGR);
                Graphics2D g2 = (Graphics2D)image.createGraphics();
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                g2.setBackground(Color.WHITE);
                Dimension d = getSize();
                g2.fillRect(0, 0, 860, 1090);
g.drawImage(image, 0, 0, null);
                               
               
                // Writes the image to a file with .jpg
                // Exits on failure
                File f = new File("image.jpg");
                try
                {
                   ImageIO.write(image, "jpg", f);
                }
                catch(IOException e)
                {
                   System.out.println("Rights conflict. Make sure device is not in use");
                   System.exit(2);
                }
}
}

Related topics
Who is your favorite actor/actress?
Can someone design me simple HTML template? or some images..
[Java] Top-Down Menu bar tweak.
mobile programmers codes
Ill deal with your HijackThis logs for you.
Java Has Failed!
Black Books
Java Problem
Know because of TV
megaupload help???
New Ipod Nano
The Genocide In Democratic South Africa
HTML5 Game Engine Development
Java vs PHP
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.