Sat Ir Picture displayed in JFrame

Satellite Pic MapComponent saved to tiff File

All labels for longitude lines at bottom and latitude lines on left and right of the map look fine when viewed in JFrame like the one used in https://docs.geotools.org/latest/userguide/tutorial/raster/image.html

File saved using saveImage function in https://docs.geotools.org/latest/userguide/library/render/gtrenderer.html

Using mapContent.getMaxBounds() as envelope to create and save the image. The green background filling of rectangle for Graphic2D image used to save in the file.
The same map seem to appear in both images attached, yet the labels at the bottom and on the right of the map (JFrame) are not included in the saved file.

Any suggestion or tip on how to debug this issue is appreciated. I am not really familiar with this geographical representations although I am learning a bit.

  • It looks like you have ended up with the size of the raster not the other layers, – Ian Turton May 2 '20 at 8:45

I've had good results using this approach:

  public void drawMapToImage(File outputFile, String outputType) {
    JMapPane mapPane = frame.getMapPane();

    try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
        ImageOutputStream outputImageFile = ImageIO.createImageOutputStream(fileOutputStream);) {
      RenderedImage bufferedImage = mapPane.getBaseImage();
      ImageIO.write(bufferedImage, outputType, outputImageFile);
    } catch (IOException ex) {
  • drawMapToImage() method proposed keeps failing mapPane.getBaseImage() returning null bufferedImage. Neither frame nor mapPane is null when used. ImageIO.write() creates an empty file. I tried using outputType="image/jpeg" ,"jpeg", and "tiff" with same result. – Isidora May 4 '20 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.