Re: saving images on a linux box

Hi Ricardo,

That JPEG logic uses the com.sun.image.codec.jpeg package.
Sun has always stated that the com.sun.* packages are not
stable or supported (that is, they are internal packages
that strictly speaking, we developers are not supposed to
be using extensively).

So, the problem is likely that there is an issue with that
package on J2sdk1.4.1_03 on Linux. First, I suggest trying
J2sdk1.4.2 beta, since I know it fixes lots of bugs. If
that doesn't work, you could use the ImageJ functionality
that is included with the VisAD distribution:

  import ij.io.FileSaver;
  ...
  Image img = display.getImage();
  File file = new File("outfile.jpg");
  FileSaver saver = new FileSaver(new ImagePlus("null", img));
  saver.saveAsJpeg(file);

-Curtis

At 11:47 AM 6/23/2003, you wrote:
>Hi all,
>
>I am having problems to save a capured image ( display.getImage() ) on my 
>Linux box the code I am using is the same that is implemented for the 
>FancySSCell and BasicSSCell.captureImage();
>
>The code works fine on my windows Laptop but when I use the very same code on 
>my Linux Box I get the following exception:
>
>java.lang.ClassCastException
>        at 
> sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:405)
>        at 
> sun.awt.image.codec.JPEGImageEncoderImpl.encode(JPEGImageEncoderImpl.java:228)
>        at AspectRatio.saveImage(AspectRatio.java:244)
>        at AspectRatio.access$100(AspectRatio.java:41)
>        at AspectRatio$4.run(AspectRatio.java:215)
>        at java.lang.Thread.run(Thread.java:536)
>
>(Note:    The exception is reported in the line encoder.encode(image); of the 
>attached code)
>
>I am using the lastest J2sdk1.4.1_03 on both my Windows and Linux machine.
>
>This is the code that I fire when I press a button:
>
>    private void snapshotActionPerformed(java.awt.event.ActionEvent evt) {
>        javax.swing.JFileChooser fc=new javax.swing.JFileChooser();
>        javax.swing.filechooser.FileFilter jpgFilter = new 
> visad.util.ExtensionFileFilter("jpg","JPEG File");
>        fc.addChoosableFileFilter(jpgFilter);
>        fc.showSaveDialog(this);
>
>        if(fc.getSelectedFile() == null) return;
>
>        final java.io.File f=fc.getSelectedFile();
>        Runnable captureImage = new Runnable() {
>          public void run() {
>            String msg = "Could not save image snapshot to file \"" + 
> f.getName() +
>              "\" in JPEG format. ";
>            try {
>              saveImage(f);
>            }
>            catch (visad.VisADException exc) {
>              msg = msg + "An error occurred: " + exc.getMessage();
>              javax.swing.JOptionPane.showMessageDialog(mainFrame, msg, "Error 
> saving data",
>                javax.swing.JOptionPane.ERROR_MESSAGE);
>            }
>            catch (IOException exc) {
>              msg = msg + "An I/O error occurred: " + exc.getMessage();
>              javax.swing.JOptionPane.showMessageDialog(mainFrame, msg, "Error 
> saving data",
>                javax.swing.JOptionPane.ERROR_MESSAGE);
>            }
>          }
>        };
>        Thread t = new Thread(captureImage);
>        t.start();
>    }
>    
>    private void saveImage(java.io.File f) throws visad.VisADException, 
> java.io.IOException {
>        java.awt.image.BufferedImage image = display.getImage();
>        
>        try {
>            if(!f.getName().endsWith(".jpg")){
>                f= new java.io.File(f.getPath()+".jpg");
>            }
>            JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(image);
>            param.setQuality(1.0f, true);
>            FileOutputStream fout = new FileOutputStream(f);
>            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fout);
>            encoder.encode(image);
>            fout.close();
>        }catch (NoClassDefFoundError err) {
>            System.err.println("Error: "+err);
>            err.printStackTrace();
>        }
>    }
>
>Thanks in advance for the help you can provide me with,
>
>Ricardo


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