Re: Saving image and scale...

Hi Carlos,

To paint any Java Component (including VisAD widgets) to an image, you should 
be able to do something like the following (although I haven't tested it):

    SelectRangeWidget srw = ...;
    Dimension size = srw.getSize();
    Image img = srw.createImage(size.width, size.height);
    Graphics g = img.getGraphics();

Now, img contains a snapshot of the component.  You can combine multiple images 
vertically with:

    BufferedImage image1 = display2.getImage();
    BufferedImage image2 = (BufferedImage) img;
    int type = image1.getType();
    int w1 = image1.getWidth();
    int h1 = image1.getHeight();
    int w2 = image2.getWidth();
    int h2 = image2.getHeight();
    BufferedImage image = new BufferedImage(w1 > w2 ? w1 : w2, h1 + h2, type);
    Graphics g = img.createGraphics();
    g.drawImage(image1, 0, 0, null);
    g.drawImage(image2, 0, h1, null);

Then save to disk with:

    FileSaver saver = new FileSaver(new ImagePlus("null", image));
    saver.saveAsTiff(file); // save in TIFF file format
    saver.saveAsJpeg(file); // save in JPEG file format
    saver.saveAsRaw(file); // save in RAW file format

Hope this helps.


At 12:54 PM 9/4/2002, Carlos Pleguezuelos wrote:
>That is not the problem. I want to make a GIF file (making first a 
>BufferedImage) with the display image (using getImage method) and the color 
>scale of the LabeledRGBWidget.
>This widget is built of 4 widgets. I have modified the code so I can get the 
>color table, the arrow and the label widget. 
>Im able to paste different BufferedImage, but calling createImage method of 
>Component the only thing I get is an empty Image, so I cant get the Image from 
>these three widgets.
>There is a way of do it using a Robot, but Im trying to avoid using it (due to 
>Applet security).
>If anybody had the same problem, please show me the solution...
>Thanks again.....
>Bill Hibbard wrote:
>>Hi Carlos,
>>>My question is: I got a a DisplayImplJ2D with a  RealType mapped to RGB.
>>>I got a LabeledRGBWidget controlling this map.
>>>Im able to write the display image to disc, but I want to take the color
>>>scale of the LabeledRGBWidget to the same image, so I can get a GIF file
>>>with the display and the scale.
>>>I dont know how to do it, and  even if I can do it, so a little help is
>>>needed!! ;-)
>>You can get the color table as follows:
>>  ScalarMap rgbMap = new ScalarMap(..., Display.RGB);
>>  . . .
>>  ColorControl control = (ColorControl) rgbMap.getControl();
>>  float[][] table = control.getTable();
>>  // now save the table with the image
>>I don't know enough about your file format to know how
>>you'd save the color table, but at least this code shows
>>you how to get the table information from VisAD.
>>Good luck,

  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: