// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

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

public class JpegCreate {
   public static void main(String[] args) {
      BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
      Graphics g = bi.getGraphics();
      g.setColor(Color.WHITE);
      g.fillRect(0, 0, 100, 100);
      g.setColor(Color.BLUE);
      g.fillOval(20, 20, 60, 60);
      try {
         JPEGImageEncoder ecd = JPEGCodec.createJPEGEncoder(new FileOutputStream("C:\\z.jpg"));
         ecd.encode(bi);
      } catch (FileNotFoundException e) {
         e.printStackTrace();
      } catch (ImageFormatException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
}
