// This program copies line segment data from a file to a png file. // Each line segment to be drawn is 4 words, 4 bytes each, in big-endian order. import java.awt.*; import java.awt.image.*; import javax.imageio.ImageIO; import java.io.*; class Main { static final int X = 700, Y = 700; static int gs(FileInputStream s) throws IOException {byte x[] = new byte[4]; int c = s.read(x, 0, 4); if(c != 4) return -1; int r = 0; for(int i=0; i<4; ++i) r = (r<<8) | (0xff&x[i]); return r;} static public void main( String[] args ) throws FileNotFoundException, IOException { FileInputStream is; BufferedImage I = new BufferedImage(X, Y, BufferedImage.TYPE_INT_RGB); Graphics2D g = I.createGraphics(); g.setColor(Color.white); try{is = new FileInputStream("trnsp");} catch(java.io.FileNotFoundException nf){ System.out.println("No input trnsp."); return;} while(true) { int x=gs(is); if (x < 0) break; g.drawLine(x, Y-1-gs(is), gs(is), Y-1-gs(is));} try {ImageIO.write(I, "png", new File("cnf.png"));} catch (IOException e) {System.err.println("image not saved.");}}}