NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
I am a newbie to VisAD. I am trying out one of the first examples with a slight modification. I am trying to render the image off-scrren, that is write out the image to a file. I tried a bunch of things but could not get it to work completely. The image is written to file, but apparently it isn't complete. Please find the code below. Appreciate any help. (Also, please CC your reply to rsm0001@xxxxxxxxxxxx). sincerely, Ramesh Mantri import visad.*; import visad.java2d.DisplayImplJ2D; import java.rmi.RemoteException; import java.awt.*; import javax.swing.*; import com.sun.image.codec.jpeg.*; import java.io.*; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; public class WriteImage { private RealType time, height; private FunctionType func_time_height; private Set time_set; private FlatField vals_ff; private DataReferenceImpl data_ref; private DisplayImpl display; private ScalarMap timeMap, heightMap; public WriteImage(String[] args) throws RemoteException, VisADException { time = new RealType("time"); height = new RealType("height"); func_time_height = new FunctionType(time, height); time_set = new Integer1DSet(time, 5); float[][] h_vals = new float[][] {{0.0f, 13.75f, 45.0f, 33.75f, 0.0f,}}; vals_ff = new FlatField(func_time_height, time_set); vals_ff.setSamples(h_vals); //display = new DisplayImplJ2D("display1"); display = new DisplayImplJ2D("display1", 450, 450); timeMap = new ScalarMap(time, Display.XAxis); heightMap = new ScalarMap(height, Display.YAxis); display.addMap(timeMap); display.addMap(heightMap); data_ref = new DataReferenceImpl("data_ref"); data_ref.setData(vals_ff); display.addReference(data_ref); } public void writeToFile() throws IOException { BufferedImage image = display.getImage(true); File file = new File("visadImage.png"); ImageIO.write(image, "PNG", file); } public static void main(String[] args) { try { WriteImage imgObj = new WriteImage(args); imgObj.writeToFile(); //System.exit(0); } catch (Exception e) { e.printStackTrace(); } } }
visad
archives: