Title: Canvas Image saving

Hello Abel:

        You could use an example called PrintCanvas3D of the demo directory of the last Java 3D Beta version. There you have an example of how extending Canvas3D for achieve the rendered image of your scene canvas with offscreen rendering.

       
        Using this example you can pass the image to a BufferedImage object, then you have to options:

                - to use JIMI package (look for it in sun's site), this package contains a lot of picture formats encondings.

                - to use a com.sun related undocumented package:
                        this one is very simple, it's inside java 2 SDK, it's com.sun.image.codec.jpeg.*

                        And the use is very simple:

   public static void saveImage(BufferedImage image, String fileRoute)
   {
      try
      {
        FileOutputStream fos = new FileOutputStream(fileRoute);
        JPEGImageEncoder jpegImageEncoder = JPEGCodec.createJPEGEncoder(fos);
        jpegImageEncoder.encode(image);
        fos.close();
      }
      catch(FileNotFoundException fnfe)
      {
        fnfe.printStackTrace();
      }
      catch(IOException ioe)
      {
        ioe.printStackTrace();
      }
      catch(Exception e)
      {
        e.printStackTrace();
      }
   }

Reply via email to