I wrote a program that reads an image from command line and want to read each pixel to draw a rectangle of the respective colour to "recreate" the image from rectangles.
However, although the rectangles have the correct size, every pixel seems to be black. At least, what I see in the output panel is a black picture that has the same size as the input picture.
    class AppDrawPanel extends JPanel {  
        private BufferedImage bi;
        /* ... */
        public void loadAPPImage( String s ) throws IOException{
             bi = ImageIO.read(new File(s));
        }
        @Override
        public void paint(Graphics g){
           Graphics2D g2 = (Graphics2D) g;
           int w = bi.getWidth();
           int h = bi.getHeight();
           for( int x = 0; x < w; x++){
                for ( int z = 0; z < h; z++ ){
                        Color c = new Color(bi.getRGB(x, z));
                        super.setForeground(c);
                        g2.fillRect(x, z, 3, 3);  
                }    
           }
        }
    }
And the main function:
    public static void main( String[] args ) throws IOException{         
        /* ... */
        AppDrawPanel draw = new AppDrawPanel();
        draw.loadAPPImage(args[0]);
        frame.add(draw);        
        /* ... */
    } 
where /* ... */ represents code that has nothing to do with drawing the rectangles or reading the image.
 
     
     
    