import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Random;

import sun.awt.image.codec.JPEGImageEncoderImpl;

import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class ImageMaker {

    public BufferedImage createImage(int widthint heightthrows IOException{
        
        BufferedImage bi = new BufferedImage(widthheightBufferedImage.TYPE_INT_RGB);
        
        Random r = new Random();
        
        r.setSeed(new Date().getTime());
        
        Graphics g = bi.getGraphics();
       
        for (int i=0i<bi.getWidth(); i++){
            for (int j=0j<bi.getHeight(); j++){
                int red = Math.abs(r.nextInt()%256);
                int green = Math.abs(r.nextInt()%256);
                int blue = Math.abs(r.nextInt()%256);
                
                Color c = new Color(redgreenblue);
                g.setColor(c);
                g.drawRect(ij00);                
            }
            System.out.println((i+1) + " of 1024 lines done");
        }

        
        bi.flush();
        
        return bi;
        
    }
    
    
    public static void main(String[] argsthrows IOException {
        
        final String FILENAME = "/Users/bfo/Desktop/random.jpg";
        
        ImageMaker im = new ImageMaker();
        
        BufferedImage bi = im.createImage(1024768);
        
        FileOutputStream fos = new FileOutputStream(FILENAME);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        
        JPEGImageEncoder e = new JPEGImageEncoderImpl(bos);
        
        e.encode(bi);
        
        bos.flush();
        bos.close();
        
        System.out.println("OK, Image saved to " + FILENAME);
    }

}