Beanshell:Saving View as Image

From OpenJUMP Wiki
Jump to navigation Jump to search

It is possible to save the current viewport as an image with File -> Save Image As...

However sometimes it may be desireable to save an image with dimensions greater than that of the screen. This can be accomplished with the following script. Replace the first line (ie "outputFile=...") with the name and path of the output image file. The next line (ie widthInPixels=...) sets the width of the image. The height is calculated automatically.

{
outputFile = "/my/path/myOutputImage.png";
widthInPixels = 1200;
import com.vividsolutions.jump.workbench.ui.LayerPrinter;
printer = new LayerPrinter();
env = wc.getLayerViewPanel().getViewport().getEnvelopeInModelCoordinates();
image = printer.print(wc.getLayerManager().getLayers(), env, widthInPixels);
import javax.imageio.ImageIO;
ImageIO.write(image, "png", new File(outputFile));
}

This plugin requires Java Advanced Imaging. This is available from http://java.sun.com/