MapView myView = MapView.createViewforMap(currentMap);
MapView myView = MapView.createViewforMap(currentMap, this);
    public void saveMapImage(String filename) {        if (filename == null) {            JFileChooser chooser = new JFileChooser();            chooser.setDialogTitle("Save as image");            if (chooser.showSaveDialog(appFrame) ==                    JFileChooser.APPROVE_OPTION) {                filename = chooser.getSelectedFile().getAbsolutePath();            }        }        if (filename != null) {            MapView myView = MapView.createViewforMap(currentMap);            myView.setShowGrid(mapView.getShowGrid());            myView.setMode(MapView.PF_NOSPECIAL, true);            myView.setZoom(mapView.getZoom());            Dimension imgSize = myView.getPreferredSize();            try {                BufferedImage img = new BufferedImage(                        imgSize.width, imgSize.height, BufferedImage.TYPE_INT_ARGB);                Graphics2D g = img.createGraphics();                g.setClip(0, 0, imgSize.width, imgSize.height);                myView.paint(g);                int lastDot = filename.lastIndexOf('.');                String format = filename.substring(lastDot + 1);                try {                    ImageIO.write(img, format, new File(filename));                } catch (IOException e) {                    e.printStackTrace();                    JOptionPane.showMessageDialog(appFrame,                            "Error while saving " + filename + ": " + e.toString(),                            "Error while saving map image",                            JOptionPane.ERROR_MESSAGE);                }            } catch (OutOfMemoryError memoryError) {                JOptionPane.showMessageDialog(appFrame,                        "Out of memory while creating image. Try increasing\n" +                                "your maximum heap size or zooming out a bit.",                        "Out of memory",                        JOptionPane.ERROR_MESSAGE);            }        }    }