// An example of image writing in Java // // Create a new png image, and save it // // REF (BufferedImage Class API): // http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/BufferedImage.html // // M. Branicky, 10/10/06 import java.awt.image.*; import javax.imageio.*; import java.io.*; public class NewImage { // 0xNUM is how to input HEXadecimal numbers (base 16: digits 0-F) in Java // See http://cloford.com/resources/colours/500col.htm for HEX color codes public static final int BLACK = 0, WHITE = 0xFFFFFF; public static void main (String args[]) throws IOException { // create a new, "blank" 300 by 300 image BufferedImage myimage = new BufferedImage(300,300,BufferedImage.TYPE_INT_RGB); // set the values for the image for (int i=0; i<300; i++) { for (int j=0; j<300; j++) { if (i%2==0) myimage.setRGB(i,j,WHITE); else myimage.setRGB(i,j,BLACK); } } // store the image in a file File outImage = new File("myimage.jpg"); ImageIO.write(myimage, "jpg", outImage); } }