private void createSnapshotImage() throws IOException {
		File outputfile = new File(snapshotimage);
		System.out.println("Save snapshot of gcode to "+snapshotimage);
		long time = System.currentTimeMillis();
		gp.setSnapshotMode();
		gp.jumptoLayer(10000);
		gp.togglePause();
		gp.setPainttravel(Travel.NOT_PAINTED);
		int lc = gp.model.getLayercount(true);
		System.out.println("Layers:"+lc);
		if(lc==0) System.exit(2);
		
		if(snapmode==1){
			//Paint 5 layers only to speed up time
			lc = Math.min(lc, 5);
		}
		
		int retry=0;
		while(gp.getCurrentLayer() == null){
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {}
			retry++;
			if(retry > 20){
				System.err.println("Timeout waiting for painter");
				System.exit(3);
			}
			
		}
		int ln=0;
		while( (ln=gp.getCurrentLayer().getNumber()) < (lc-1) ){
			try {
				Thread.sleep(500);
				System.out.print(".");
			} catch (InterruptedException e) {
		}
		}
		int[] sz = gp.getSize(false);
		BufferedImage dest = awt.offimg.getSubimage(0, 0, sz[0]-gp.getGap(), sz[1]);
		ImageIO.write(dest, "jpg", outputfile);
		System.out.println("\nDone (Time: "+ (System.currentTimeMillis()-time)+")");
		System.exit(0);
	}