Hi guys here is how I was able to create image from
createMap()
{
theFrame = new JFrame();
....more code here
map = new JMap(reference,initialExtent);
theFrame.getContentPane().add(map);
ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(worldStreetMap);
map.getLayers().add(tiledLayer);
map.setExtent(initialExtent);
theFrame.setVisible(true) ;
Thread.sleep(30000); //Sleep untill all the layers are added
createImage(map);
//Close the frame after image taken place( to avoid manual closing)
WindowEvent windowClosing = new WindowEvent(theFrame, WindowEvent.WINDOW_CLOSING);
theFrame.dispatchEvent(windowClosing);
}
public static BufferedImage createImage(Component panel)
{
int w = panel.getWidth();
int h = panel.getHeight();
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
panel.paintAll(g);
File file = new File(filePath);
ImageIO.write(bi, "png", file); // ignore returned boolean
}