Class ContourPlot.ImageSaver

  • Enclosing class:
    ContourPlot

    public static class ContourPlot.ImageSaver
    extends java.lang.Object
    Class providing convenience methods for saving Images to file.
    Since:
    1.0
    Author:
    hageldave
    • Constructor Detail

      • ImageSaver

        private ImageSaver()
    • Method Detail

      • getSaveableImageFileFormats

        public static java.lang.String[] getSaveableImageFileFormats()
        Returns:
        ImageIO.getWriterFileSuffixes()
        Since:
        1.0
      • isFormatRGBOnly

        public static boolean isFormatRGBOnly​(java.lang.String imgFormat)
        returns if specified image format supports rgb values only. This means argb values probably need conversion beforehand.
        Parameters:
        imgFormat - the file format e.g. jpg or png
        Returns:
        true if format only supports rgb values
        Since:
        1.0
      • isFormatBWOnly

        public static boolean isFormatBWOnly​(java.lang.String imgFormat)
      • saveImage

        public static void saveImage​(java.awt.Image image,
                                     java.io.OutputStream os,
                                     java.lang.String imgFileFormat)
        Saves specified Image to file of specified img file format.

        Some image file formats may require image type conversion before saving. This method converts to type INT_RGB for jpg, jpeg and bmp, and to type BYTE_BINARY for wbmp.

        The provided OutputStream will not be closed, this is the responsibility of the caller.

        Parameters:
        image - to be saved
        os - OutputStream to write image to.
        imgFileFormat - image file format. Consult getSaveableImageFileFormats() to get the supported img file formats of your system.
        Throws:
        ContourPlot.ImageSaver.ImageSaverException - if an IOException occurred during the process or no appropriate writer could be found for specified format.
        Since:
        1.1
      • isBufferedImageOfType

        private static final boolean isBufferedImageOfType​(java.awt.Image image,
                                                           int type)
      • saveImage

        public static void saveImage​(java.awt.Image image,
                                     java.lang.String filename,
                                     java.lang.String imgFileFormat)
        Parameters:
        image - to be saved
        filename - path to file
        imgFileFormat - image file format. Consult getSaveableImageFileFormats()
        Throws:
        ContourPlot.ImageSaver.ImageSaverException - if an IOException occurred during the process, the provided filename path does refer to a directory or no appropriate writer could be found for specified format.
        Since:
        1.0
      • saveImage

        public static void saveImage​(java.awt.Image image,
                                     java.io.File file,
                                     java.lang.String imgFileFormat)
        Parameters:
        image - to be saved
        file - to save image to
        imgFileFormat - image file format. Consult getSaveableImageFileFormats()
        Throws:
        ContourPlot.ImageSaver.ImageSaverException - if an IOException occurred during the process, no OutputStream could be created due to a FileNotFoundException or no appropriate writer could be found for specified format.
        Since:
        1.0
      • saveImage

        public static void saveImage​(java.awt.Image image,
                                     java.io.File file)
        Saves Image using saveImage(Image, File, String). The file format is extracted from the files name.
        Parameters:
        image - to be saved
        file - to save image to
        Throws:
        ContourPlot.ImageSaver.ImageSaverException - if an IOException occurred during the process, the filename does not contain a dot to get the filetype or no appropriate writer could be found for specified format.
        Since:
        1.0
      • saveImage

        public static void saveImage​(java.awt.Image image,
                                     java.lang.String filename)
        Saves Image using saveImage(Image, File). The file format is extracted from the files name.
        Parameters:
        image - to be saved
        filename - path to file to save image to
        Throws:
        ContourPlot.ImageSaver.ImageSaverException - if an IOException occurred during the process, the filename does not contain a dot to get the filetype, the provided filename path does refer to a directory, or no appropriate writer could be found for specified format.
        Since:
        1.0