public static void saveToPng(Maze m, Path to, boolean withShortestPath)
			throws IOException {
		Logger logger = Logger.getLogger("fr.upem.algoproject");
		int width = m.getWidth();
		int bi_w = Math.max(100, width);
		int bi_h = Math.max(100, m.getHeight());
		BufferedImage bi = new BufferedImage(bi_w, bi_h,
				BufferedImage.TYPE_INT_ARGB);
		logger.finest("Filling image with blue...");
		for (int i = 0; i < bi_w; i++) {
			for (int j = 0; j < bi_h; j++) {
				bi.setRGB(i, j, Color.BLUE.getRGB());
			}
		}
		logger.finest("Trying to paint white over the blue to represent the pathes");
		for (Integer i : m.getGraph().getAllNodes()) {
			if (m.getGraph().getNeighbours(i).isEmpty()) {
				continue;
			}
			int y = i / width;
			int x = i % width;
			setTile(bi, Color.WHITE.getRGB(), bi_w, bi_h, width, m.getHeight(),
					x, y);
		}
		setTile(bi, Color.RED.getRGB(), bi_w, bi_h, width, m.getHeight(),
				m.getStart().x, m.getStart().y);
		setTile(bi, Color.RED.getRGB(), bi_w, bi_h, width, m.getHeight(),
				m.getEnd().x, m.getEnd().y);
		if (withShortestPath) {
			int shortestPath[] = m.getShortestPath();
			int end = m.getEnd().y * width + m.getEnd().x;
			int start = m.getStart().y * width + m.getStart().x;
			int u = end;
			while (shortestPath[u] != -1) {
				setTile(bi, Color.GREEN.getRGB(), bi_w, bi_h, width,
						m.getHeight(), u % width, u / width);
				u = shortestPath[u];
			}
		}
		File outputfile = to.toFile();
		ImageIO.write(bi, "png", outputfile);
		logger.info("Done writing to file" + to.toAbsolutePath());
	}