BufferedImage myImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = myImage.createGraphics();
g.setPaint(Color.WHITE);
g.fillRect(0,0, width, height);
SwingGraphicsAdapter sg = new SwingGraphicsAdapter(g);
double scale = getScale(nanograph, sg);
g.scale(scale, scale);
paintImage(sg);
try {
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);