org.apache.commons.imaging

## Class Imaging

- java.lang.Object
- - org.apache.commons.imaging.Imaging

-     public final class Imaging
      extends Object

  The primary application programming interface (API) to the Imaging library.

  ## Application Notes

  ### Using this class

  Almost all of the Apache Commons Imaging library's core functionality can be accessed through the methods provided by this class. The use of the Imaging class is similar to the Java API's ImageIO class, though Imaging supports formats and options not included in the standard Java API.

  All of methods provided by the Imaging class are declared static.

  The Apache Commons Imaging package is a pure Java implementation.

  ### Format support

  While the Apache Commons Imaging package handles a number of different graphics formats, support for some formats is not yet complete. For the most recent information on support for specific formats, refer to Format Support at the main project development web site.

  ### Optional parameters for image reading and writing

  Some of the methods provided by this class accept an optional params argument that permits the application to specify elements for special handling. If these specifications are not required by the application, the params argument may be omitted (as appropriate) or a null argument may be provided. In image-writing operations, the option parameters may include options such as data-compression type (if any), color model, or other format-specific data representations. The parameters map may also be used to provide EXIF Tags and other metadata to those formats that support them. In image-reading operations, the parameters may include information about special handling in reading the image data.

  Optional parameters are specified using a Map object (typically, a Java HashMap) to specify a set of keys and values for input. The specification for support keys is provided by the ImagingConstants interface as well as by format-specific interfaces such as JpegContants or TiffConstants.

  ### Example code

  See the source of the SampleUsage class and other classes in the org.apache.commons.imaging.examples package for examples.

  See Also:
    org.apache.commons.imaging.examples.SampleUsage, Format Support

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `dumpImageFile(byte[] bytes)` Write the ImageInfo and format-specific information for the image content of the specified byte array to a string.
    `static String` | `dumpImageFile(File file)` Write the ImageInfo and format-specific information for the image content of the specified file to a string.
    `static List<BufferedImage>` | `getAllBufferedImages(byte[] bytes)` Gets all images specified by the byte array (some formats may include multiple images within a single data source).
    `static List<BufferedImage>` | `getAllBufferedImages(File file)` Gets all images specified by the file (some formats may include multiple images within a single data source).
    `static List<BufferedImage>` | `getAllBufferedImages(InputStream is, String fileName)` Gets all images specified by the InputStream (some formats may include multiple images within a single data source).
    `static BufferedImage` | `getBufferedImage(byte[] bytes)` Reads the first image from a byte array.
    `static BufferedImage` | `getBufferedImage(byte[] bytes, Map<String,Object> params)` Reads the first image from a byte array using data-processing options specified through a parameters map.
    `static BufferedImage` | `getBufferedImage(File file)` Reads the first image from a file.
    `static BufferedImage` | `getBufferedImage(File file, Map<String,Object> params)` Reads the first image from a file using data-processing options specified through a parameters map.
    `static BufferedImage` | `getBufferedImage(InputStream is)` Reads the first image from an InputStream.
    `static BufferedImage` | `getBufferedImage(InputStream is, Map<String,Object> params)` Reads the first image from an InputStream using data-processing options specified through a parameters map.
    `static FormatCompliance` | `getFormatCompliance(byte[] bytes)` Attempts to determine the image format of the specified data and evaluates its format compliance.
    `static FormatCompliance` | `getFormatCompliance(File file)` Attempts to determine the image format of the specified data and evaluates its format compliance.
    `static ICC_Profile` | `getICCProfile(byte[] bytes)` Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `static ICC_Profile` | `getICCProfile(byte[] bytes, Map<String,Object> params)` Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `protected static ICC_Profile` | `getICCProfile(ByteSource byteSource, Map<String,Object> params)`
    `static ICC_Profile` | `getICCProfile(File file)` Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `static ICC_Profile` | `getICCProfile(File file, Map<String,Object> params)` Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `static ICC_Profile` | `getICCProfile(InputStream is, String fileName)` Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `static ICC_Profile` | `getICCProfile(InputStream is, String fileName, Map<String,Object> params)` Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `static byte[]` | `getICCProfileBytes(byte[] bytes)` Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `static byte[]` | `getICCProfileBytes(byte[] bytes, Map<String,Object> params)` Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `static byte[]` | `getICCProfileBytes(File file)` Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `static byte[]` | `getICCProfileBytes(File file, Map<String,Object> params)` Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
    `static ImageInfo` | `getImageInfo(byte[] bytes)` Parses the "image info" of an image.
    `static ImageInfo` | `getImageInfo(byte[] bytes, Map<String,Object> params)` Parses the "image info" of an image.
    `static ImageInfo` | `getImageInfo(File file)` Parses the "image info" of an image file.
    `static ImageInfo` | `getImageInfo(File file, Map<String,Object> params)` Parses the "image info" of an image file.
    `static ImageInfo` | `getImageInfo(InputStream is, String fileName)` Parses the "image info" of an image.
    `static ImageInfo` | `getImageInfo(InputStream is, String fileName, Map<String,Object> params)` Parses the "image info" of an image.
    `static ImageInfo` | `getImageInfo(String fileName, byte[] bytes)` Parses the "image info" of an image.
    `static ImageInfo` | `getImageInfo(String fileName, byte[] bytes, Map<String,Object> params)` Parses the "image info" of an image.
    `static Dimension` | `getImageSize(byte[] bytes)` Determines the width and height of an image.
    `static Dimension` | `getImageSize(byte[] bytes, Map<String,Object> params)` Determines the width and height of an image.
    `static Dimension` | `getImageSize(ByteSource byteSource, Map<String,Object> params)`
    `static Dimension` | `getImageSize(File file)` Determines the width and height of an image file.
    `static Dimension` | `getImageSize(File file, Map<String,Object> params)` Determines the width and height of an image file.
    `static Dimension` | `getImageSize(InputStream is, String fileName)` Determines the width and height of an image.
    `static Dimension` | `getImageSize(InputStream is, String fileName, Map<String,Object> params)` Determines the width and height of an image.
    `static ImageMetadata` | `getMetadata(byte[] bytes)` Parses the metadata of an image.
    `static ImageMetadata` | `getMetadata(byte[] bytes, Map<String,Object> params)` Parses the metadata of an image.
    `static ImageMetadata` | `getMetadata(File file)` Parses the metadata of an image file.
    `static ImageMetadata` | `getMetadata(File file, Map<String,Object> params)` Parses the metadata of an image file.
    `static ImageMetadata` | `getMetadata(InputStream is, String fileName)` Parses the metadata of an image file.
    `static ImageMetadata` | `getMetadata(InputStream is, String fileName, Map<String,Object> params)` Parses the metadata of an image file.
    `static String` | `getXmpXml(byte[] bytes)` Extracts the embedded XML metadata as an XML string.
    `static String` | `getXmpXml(byte[] bytes, Map<String,Object> params)` Extracts the embedded XML metadata as an XML string.
    `static String` | `getXmpXml(ByteSource byteSource, Map<String,Object> params)` Extracts the embedded XML metadata as an XML string.
    `static String` | `getXmpXml(File file)` Extracts the embedded XML metadata as an XML string.
    `static String` | `getXmpXml(File file, Map<String,Object> params)` Extracts the embedded XML metadata as an XML string.
    `static String` | `getXmpXml(InputStream is, String fileName)` Extracts the embedded XML metadata as an XML string.
    `static String` | `getXmpXml(InputStream is, String fileName, Map<String,Object> params)` Extracts the embedded XML metadata as an XML string.
    `static ImageFormat` | `guessFormat(byte[] bytes)` Attempts to determine the image format of a file based on its "magic numbers," the first bytes of the data.
    `static ImageFormat` | `guessFormat(ByteSource byteSource)` Attempts to determine the image format of a file based on its "magic numbers," the first bytes of the data.
    `static ImageFormat` | `guessFormat(File file)` Attempts to determine the image format of a file based on its "magic numbers," the first bytes of the data.
    `static boolean` | `hasImageFileExtension(File file)` Attempts to determine if a file contains an image recorded in a supported graphics format based on its file-name extension (for example ".jpg", ".gif", ".png", etc.).
    `static boolean` | `hasImageFileExtension(String fileName)` Attempts to determine if a file contains an image recorded in a supported graphics format based on its file-name extension (for example ".jpg", ".gif", ".png", etc.).
    `static void` | `writeImage(BufferedImage src, File file, ImageFormat format, Map<String,Object> params)` Writes the content of a BufferedImage to a file using the specified image format.
    `static void` | `writeImage(BufferedImage src, OutputStream os, ImageFormat format, Map<String,Object> params)` Writes the content of a BufferedImage to an OutputStream using the specified image format.
    `static byte[]` | `writeImageToBytes(BufferedImage src, ImageFormat format, Map<String,Object> params)` Writes the content of a BufferedImage to a byte array using the specified image format.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### hasImageFileExtension

          public static boolean hasImageFileExtension(File file)

      Attempts to determine if a file contains an image recorded in a supported graphics format based on its file-name extension (for example ".jpg", ".gif", ".png", etc.).
      Parameters:
        `file` - A valid File object providing a reference to a file that may contain an image.
      Returns:
        true if the file-name includes a supported image format file extension; otherwise, false.

    - #### hasImageFileExtension

          public static boolean hasImageFileExtension(String fileName)

      Attempts to determine if a file contains an image recorded in a supported graphics format based on its file-name extension (for example ".jpg", ".gif", ".png", etc.).
      Parameters:
        `fileName` - A valid string representing name of file which may contain an image.
      Returns:
        true if the file name has an image format file extension.

    - #### guessFormat

          public static ImageFormat guessFormat(byte[] bytes)
                                         throws ImageReadException,
                                                IOException

      Attempts to determine the image format of a file based on its "magic numbers," the first bytes of the data.

      Many graphics format specify identifying byte values that appear at the beginning of the data file. This method checks for such identifying elements and returns a ImageFormat enumeration indicating what it detects. Note that this method can return "false positives" in cases where non-image files begin with the specified byte values.

      Parameters:
        `bytes` - Byte array containing an image file.
      Returns:
        An ImageFormat, such as ImageFormat.IMAGE_FORMAT_JPEG. Returns ImageFormat.IMAGE_FORMAT_UNKNOWN if the image type cannot be determined.
      Throws:
        `ImageReadException` - in the event of an unsuccessful attempt to read the image data
        `IOException` - in the event of an unrecoverable I/O condition.

    - #### guessFormat

          public static ImageFormat guessFormat(File file)
                                         throws ImageReadException,
                                                IOException

      Attempts to determine the image format of a file based on its "magic numbers," the first bytes of the data.

      Many graphics formats specify identifying byte values that appear at the beginning of the data file. This method checks for such identifying elements and returns a ImageFormat enumeration indicating what it detects. Note that this method can return "false positives" in cases where non-image files begin with the specified byte values.

      Parameters:
        `file` - File containing image data.
      Returns:
        An ImageFormat, such as ImageFormat.IMAGE_FORMAT_JPEG. Returns ImageFormat.IMAGE_FORMAT_UNKNOWN if the image type cannot be determined.
      Throws:
        `ImageReadException` - in the event of an unsuccessful attempt to read the image data
        `IOException` - in the event of an unrecoverable I/O condition.

    - #### guessFormat

          public static ImageFormat guessFormat(ByteSource byteSource)
                                         throws ImageReadException,
                                                IOException

      Attempts to determine the image format of a file based on its "magic numbers," the first bytes of the data.

      Many graphics formats specify identifying byte values that appear at the beginning of the data file. This method checks for such identifying elements and returns a ImageFormat enumeration indicating what it detects. Note that this method can return "false positives" in cases where non-image files begin with the specified byte values.

      Parameters:
        `byteSource` - a valid ByteSource object potentially supplying data for an image.
      Returns:
        An ImageFormat, such as ImageFormat.IMAGE_FORMAT_JPEG. Returns ImageFormat.IMAGE_FORMAT_UNKNOWN if the image type cannot be determined.
      Throws:
        `ImageReadException` - in the event of an unsuccessful attempt to read the image data
        `IOException` - in the event of an unrecoverable I/O condition.

    - #### getICCProfile

          public static ICC_Profile getICCProfile(byte[] bytes)
                                           throws ImageReadException,
                                                  IOException

      Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
      Parameters:
        `bytes` - Byte array containing an image file.
      Returns:
        An instance of ICC_Profile or null if the image contains no ICC profile.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getICCProfile

          public static ICC_Profile getICCProfile(byte[] bytes,
                                                  Map<String,Object> params)
                                           throws ImageReadException,
                                                  IOException

      Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
      Parameters:
        `bytes` - Byte array containing an image file.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of ICC_Profile or null if the image contains no ICC profile.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getICCProfile

          public static ICC_Profile getICCProfile(InputStream is,
                                                  String fileName)
                                           throws ImageReadException,
                                                  IOException

      Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
      Returns:
        An instance of ICC_Profile or null if the image contains no ICC profile.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getICCProfile

          public static ICC_Profile getICCProfile(InputStream is,
                                                  String fileName,
                                                  Map<String,Object> params)
                                           throws ImageReadException,
                                                  IOException

      Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of ICC_Profile or null if the image contains no ICC profile.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getICCProfile

          public static ICC_Profile getICCProfile(File file)
                                           throws ImageReadException,
                                                  IOException

      Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
      Parameters:
        `file` - File containing image data.
      Returns:
        An instance of ICC_Profile or null if the image contains no ICC profile.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getICCProfile

          public static ICC_Profile getICCProfile(File file,
                                                  Map<String,Object> params)
                                           throws ImageReadException,
                                                  IOException

      Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
      Parameters:
        `file` - File containing image data.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of ICC_Profile or null if the image contains no ICC profile.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getICCProfile

          protected static ICC_Profile getICCProfile(ByteSource byteSource,
                                                     Map<String,Object> params)
                                              throws ImageReadException,
                                                     IOException

      Throws:
        `ImageReadException`
        `IOException`

    - #### getICCProfileBytes

          public static byte[] getICCProfileBytes(byte[] bytes)
                                           throws ImageReadException,
                                                  IOException

      Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.

      To parse the result use IccProfileParser or ICC_Profile.getInstance(bytes).

      Parameters:
        `bytes` - Byte array containing an image file.
      Returns:
        A byte array.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `IccProfileParser`, `ICC_Profile`

    - #### getICCProfileBytes

          public static byte[] getICCProfileBytes(byte[] bytes,
                                                  Map<String,Object> params)
                                           throws ImageReadException,
                                                  IOException

      Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.

      To parse the result use IccProfileParser or ICC_Profile.getInstance(bytes).

      Parameters:
        `bytes` - Byte array containing an image file.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        A byte array.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `IccProfileParser`, `ICC_Profile`

    - #### getICCProfileBytes

          public static byte[] getICCProfileBytes(File file)
                                           throws ImageReadException,
                                                  IOException

      Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.

      To parse the result use IccProfileParser or ICC_Profile.getInstance(bytes).

      Parameters:
        `file` - File containing image data.
      Returns:
        A byte array.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `IccProfileParser`, `ICC_Profile`

    - #### getICCProfileBytes

          public static byte[] getICCProfileBytes(File file,
                                                  Map<String,Object> params)
                                           throws ImageReadException,
                                                  IOException

      Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.

      To parse the result use IccProfileParser or ICC_Profile.getInstance(bytes).

      Parameters:
        `file` - File containing image data.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        A byte array.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `IccProfileParser`, `ICC_Profile`

    - #### getImageInfo

          public static ImageInfo getImageInfo(String fileName,
                                               byte[] bytes,
                                               Map<String,Object> params)
                                        throws ImageReadException,
                                               IOException

      Parses the "image info" of an image.

      "Image info" is a summary of basic information about the image such as: width, height, file format, bit depth, color type, etc.

      Not to be confused with "image metadata."

      Parameters:
        `fileName` - String.
        `bytes` - Byte array containing an image file.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of ImageInfo.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `ImageInfo`

    - #### getImageInfo

          public static ImageInfo getImageInfo(String fileName,
                                               byte[] bytes)
                                        throws ImageReadException,
                                               IOException

      Parses the "image info" of an image.

      "Image info" is a summary of basic information about the image such as: width, height, file format, bit depth, color type, etc.

      Not to be confused with "image metadata."

      Parameters:
        `fileName` - String.
        `bytes` - Byte array containing an image file.
      Returns:
        An instance of ImageInfo.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `ImageInfo`

    - #### getImageInfo

          public static ImageInfo getImageInfo(InputStream is,
                                               String fileName)
                                        throws ImageReadException,
                                               IOException

      Parses the "image info" of an image.

      "Image info" is a summary of basic information about the image such as: width, height, file format, bit depth, color type, etc.

      Not to be confused with "image metadata."

      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
      Returns:
        An instance of ImageInfo.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `ImageInfo`

    - #### getImageInfo

          public static ImageInfo getImageInfo(InputStream is,
                                               String fileName,
                                               Map<String,Object> params)
                                        throws ImageReadException,
                                               IOException

      Parses the "image info" of an image.

      "Image info" is a summary of basic information about the image such as: width, height, file format, bit depth, color type, etc.

      Not to be confused with "image metadata."

      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of ImageInfo.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `ImageInfo`

    - #### getImageInfo

          public static ImageInfo getImageInfo(byte[] bytes)
                                        throws ImageReadException,
                                               IOException

      Parses the "image info" of an image.

      "Image info" is a summary of basic information about the image such as: width, height, file format, bit depth, color type, etc.

      Not to be confused with "image metadata."

      Parameters:
        `bytes` - Byte array containing an image file.
      Returns:
        An instance of ImageInfo.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `ImageInfo`

    - #### getImageInfo

          public static ImageInfo getImageInfo(byte[] bytes,
                                               Map<String,Object> params)
                                        throws ImageReadException,
                                               IOException

      Parses the "image info" of an image.

      "Image info" is a summary of basic information about the image such as: width, height, file format, bit depth, color type, etc.

      Not to be confused with "image metadata."

      Parameters:
        `bytes` - Byte array containing an image file.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of ImageInfo.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `ImageInfo`

    - #### getImageInfo

          public static ImageInfo getImageInfo(File file,
                                               Map<String,Object> params)
                                        throws ImageReadException,
                                               IOException

      Parses the "image info" of an image file.

      "Image info" is a summary of basic information about the image such as: width, height, file format, bit depth, color type, etc.

      Not to be confused with "image metadata."

      Parameters:
        `file` - File containing image data.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of ImageInfo.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `ImageInfo`

    - #### getImageInfo

          public static ImageInfo getImageInfo(File file)
                                        throws ImageReadException,
                                               IOException

      Parses the "image info" of an image file.

      "Image info" is a summary of basic information about the image such as: width, height, file format, bit depth, color type, etc.

      Not to be confused with "image metadata."

      Parameters:
        `file` - File containing image data.
      Returns:
        An instance of ImageInfo.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data
      See Also:
        `ImageInfo`

    - #### getImageSize

          public static Dimension getImageSize(InputStream is,
                                               String fileName)
                                        throws ImageReadException,
                                               IOException

      Determines the width and height of an image.

      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
      Returns:
        The width and height of the image.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getImageSize

          public static Dimension getImageSize(InputStream is,
                                               String fileName,
                                               Map<String,Object> params)
                                        throws ImageReadException,
                                               IOException

      Determines the width and height of an image.

      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        The width and height of the image.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getImageSize

          public static Dimension getImageSize(byte[] bytes)
                                        throws ImageReadException,
                                               IOException

      Determines the width and height of an image.

      Parameters:
        `bytes` - Byte array containing an image file.
      Returns:
        The width and height of the image.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getImageSize

          public static Dimension getImageSize(byte[] bytes,
                                               Map<String,Object> params)
                                        throws ImageReadException,
                                               IOException

      Determines the width and height of an image.

      Parameters:
        `bytes` - Byte array containing an image file.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        The width and height of the image.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getImageSize

          public static Dimension getImageSize(File file)
                                        throws ImageReadException,
                                               IOException

      Determines the width and height of an image file.

      Parameters:
        `file` - File containing image data.
      Returns:
        The width and height of the image.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getImageSize

          public static Dimension getImageSize(File file,
                                               Map<String,Object> params)
                                        throws ImageReadException,
                                               IOException

      Determines the width and height of an image file.

      Parameters:
        `file` - File containing image data.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        The width and height of the image.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getImageSize

          public static Dimension getImageSize(ByteSource byteSource,
                                               Map<String,Object> params)
                                        throws ImageReadException,
                                               IOException

      Throws:
        `ImageReadException`
        `IOException`

    - #### getXmpXml

          public static String getXmpXml(InputStream is,
                                         String fileName)
                                  throws ImageReadException,
                                         IOException

      Extracts the embedded XML metadata as an XML string.

      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
      Returns:
        Xmp Xml as String, if present. Otherwise, returns null.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getXmpXml

          public static String getXmpXml(InputStream is,
                                         String fileName,
                                         Map<String,Object> params)
                                  throws ImageReadException,
                                         IOException

      Extracts the embedded XML metadata as an XML string.

      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        Xmp Xml as String, if present. Otherwise, returns null.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getXmpXml

          public static String getXmpXml(byte[] bytes)
                                  throws ImageReadException,
                                         IOException

      Extracts the embedded XML metadata as an XML string.

      Parameters:
        `bytes` - Byte array containing an image file.
      Returns:
        Xmp Xml as String, if present. Otherwise, returns null.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getXmpXml

          public static String getXmpXml(byte[] bytes,
                                         Map<String,Object> params)
                                  throws ImageReadException,
                                         IOException

      Extracts the embedded XML metadata as an XML string.

      Parameters:
        `bytes` - Byte array containing an image file.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        Xmp Xml as String, if present. Otherwise, returns null.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getXmpXml

          public static String getXmpXml(File file)
                                  throws ImageReadException,
                                         IOException

      Extracts the embedded XML metadata as an XML string.

      Parameters:
        `file` - File containing image data.
      Returns:
        Xmp Xml as String, if present. Otherwise, returns null.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getXmpXml

          public static String getXmpXml(File file,
                                         Map<String,Object> params)
                                  throws ImageReadException,
                                         IOException

      Extracts the embedded XML metadata as an XML string.

      Parameters:
        `file` - File containing image data.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        Xmp Xml as String, if present. Otherwise, returns null.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getXmpXml

          public static String getXmpXml(ByteSource byteSource,
                                         Map<String,Object> params)
                                  throws ImageReadException,
                                         IOException

      Extracts the embedded XML metadata as an XML string.

      Parameters:
        `byteSource` - File containing image data.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        Xmp Xml as String, if present. Otherwise, returns null.
      Throws:
        `ImageReadException` - if it fails to parse the image
        `IOException` - if it fails to read the image data

    - #### getMetadata

          public static ImageMetadata getMetadata(byte[] bytes)
                                           throws ImageReadException,
                                                  IOException

      Parses the metadata of an image. This metadata depends on the format of the image.

      JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may contain comments. TIFF files may contain metadata.

      The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).

      Not to be confused with "image info."

      Parameters:
        `bytes` - Byte array containing an image file.
      Returns:
        An instance of IImageMetadata.
      Throws:
        `ImageReadException` - if it fails to read the image metadata
        `IOException` - if it fails to read the image data
      See Also:
        `ImageMetadata`

    - #### getMetadata

          public static ImageMetadata getMetadata(byte[] bytes,
                                                  Map<String,Object> params)
                                           throws ImageReadException,
                                                  IOException

      Parses the metadata of an image. This metadata depends on the format of the image.

      JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may contain comments. TIFF files may contain metadata.

      The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).

      Not to be confused with "image info."

      Parameters:
        `bytes` - Byte array containing an image file.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of IImageMetadata.
      Throws:
        `ImageReadException` - if it fails to read the image metadata
        `IOException` - if it fails to read the image data
      See Also:
        `ImageMetadata`

    - #### getMetadata

          public static ImageMetadata getMetadata(InputStream is,
                                                  String fileName)
                                           throws ImageReadException,
                                                  IOException

      Parses the metadata of an image file. This metadata depends on the format of the image.

      JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may contain comments. TIFF files may contain metadata.

      The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).

      Not to be confused with "image info."

      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
      Returns:
        An instance of IImageMetadata.
      Throws:
        `ImageReadException` - if it fails to read the image metadata
        `IOException` - if it fails to read the image data
      See Also:
        `ImageMetadata`

    - #### getMetadata

          public static ImageMetadata getMetadata(InputStream is,
                                                  String fileName,
                                                  Map<String,Object> params)
                                           throws ImageReadException,
                                                  IOException

      Parses the metadata of an image file. This metadata depends on the format of the image.

      JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may contain comments. TIFF files may contain metadata.

      The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).

      Not to be confused with "image info."

      Parameters:
        `is` - InputStream from which to read image data.
        `fileName` - Filename associated with image data (optional).
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of IImageMetadata.
      Throws:
        `ImageReadException` - if it fails to read the image metadata
        `IOException` - if it fails to read the image data
      See Also:
        `ImageMetadata`

    - #### getMetadata

          public static ImageMetadata getMetadata(File file)
                                           throws ImageReadException,
                                                  IOException

      Parses the metadata of an image file. This metadata depends on the format of the image.

      JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may contain comments. TIFF files may contain metadata.

      The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).

      Not to be confused with "image info."

      Parameters:
        `file` - File containing image data.
      Returns:
        An instance of IImageMetadata.
      Throws:
        `ImageReadException` - if it fails to read the image metadata
        `IOException` - if it fails to read the image data
      See Also:
        `ImageMetadata`

    - #### getMetadata

          public static ImageMetadata getMetadata(File file,
                                                  Map<String,Object> params)
                                           throws ImageReadException,
                                                  IOException

      Parses the metadata of an image file. This metadata depends on the format of the image.

      JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may contain comments. TIFF files may contain metadata.

      The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).

      Not to be confused with "image info."

      Parameters:
        `file` - File containing image data.
        `params` - Map of optional parameters, defined in ImagingConstants.
      Returns:
        An instance of IImageMetadata.
      Throws:
        `ImageReadException` - if it fails to read the image metadata
        `IOException` - if it fails to read the image data
      See Also:
        `ImageMetadata`

    - #### dumpImageFile

          public static String dumpImageFile(byte[] bytes)
                                      throws ImageReadException,
                                             IOException

      Write the ImageInfo and format-specific information for the image content of the specified byte array to a string.
      Parameters:
        `bytes` - A valid array of bytes.
      Returns:
        A valid string.
      Throws:
        `ImageReadException` - In the event that the specified content does not conform to the format of the specific parser implementation.
        `IOException` - In the event of unsuccessful read or access operation.

    - #### dumpImageFile

          public static String dumpImageFile(File file)
                                      throws ImageReadException,
                                             IOException

      Write the ImageInfo and format-specific information for the image content of the specified file to a string.
      Parameters:
        `file` - A valid file reference.
      Returns:
        A valid string.
      Throws:
        `ImageReadException` - In the event that the specified content does not conform to the format of the specific parser implementation.
        `IOException` - In the event of unsuccessful read or access operation.

    - #### getFormatCompliance

          public static FormatCompliance getFormatCompliance(byte[] bytes)
                                                      throws ImageReadException,
                                                             IOException

      Attempts to determine the image format of the specified data and evaluates its format compliance. This method returns a FormatCompliance object which includes information about the data's compliance to a specific format.
      Parameters:
        `bytes` - a valid array of bytes containing image data.
      Returns:
        if successful, a valid FormatCompliance object.
      Throws:
        `ImageReadException` - in the event of unreadable data.
        `IOException` - in the event of an unrecoverable I/O condition.

    - #### getFormatCompliance

          public static FormatCompliance getFormatCompliance(File file)
                                                      throws ImageReadException,
                                                             IOException

      Attempts to determine the image format of the specified data and evaluates its format compliance. This method returns a FormatCompliance object which includes information about the data's compliance to a specific format.
      Parameters:
        `file` - valid file containing image data
      Returns:
        if successful, a valid FormatCompliance object.
      Throws:
        `ImageReadException` - in the event of unreadable data.
        `IOException` - in the event of an unrecoverable I/O condition.

    - #### getAllBufferedImages

          public static List<BufferedImage> getAllBufferedImages(InputStream is,
                                                                 String fileName)
                                                          throws ImageReadException,
                                                                 IOException

      Gets all images specified by the InputStream (some formats may include multiple images within a single data source).
      Parameters:
        `is` - A valid InputStream
        `fileName` - image file name
      Returns:
        A valid (potentially empty) list of BufferedImage objects.
      Throws:
        `ImageReadException` - In the event that the specified content does not conform to the format of the specific parser implementation.
        `IOException` - In the event of unsuccessful read or access operation.

    - #### getAllBufferedImages

          public static List<BufferedImage> getAllBufferedImages(byte[] bytes)
                                                          throws ImageReadException,
                                                                 IOException

      Gets all images specified by the byte array (some formats may include multiple images within a single data source).
      Parameters:
        `bytes` - a valid array of bytes
      Returns:
        A valid (potentially empty) list of BufferedImage objects.
      Throws:
        `ImageReadException` - In the event that the specified content does not conform to the format of the specific parser implementation.
        `IOException` - In the event of unsuccessful read or access operation.

    - #### getAllBufferedImages

          public static List<BufferedImage> getAllBufferedImages(File file)
                                                          throws ImageReadException,
                                                                 IOException

      Gets all images specified by the file (some formats may include multiple images within a single data source).
      Parameters:
        `file` - A reference to a valid data file.
      Returns:
        A valid (potentially empty) list of BufferedImage objects.
      Throws:
        `ImageReadException` - In the event that the specified content does not conform to the format of the specific parser implementation.
        `IOException` - In the event of unsuccessful read or access operation.

    - #### getBufferedImage

          public static BufferedImage getBufferedImage(InputStream is)
                                                throws ImageReadException,
                                                       IOException

      Reads the first image from an InputStream.

      For the most recent information on support for specific formats, refer to Format Support at the main project development web site. While the Apache Commons Imaging package does not fully support all formats, it can read image info, metadata and ICC profiles from all image formats that provide this data.

      Parameters:
        `is` - a valid ImageStream from which to read data.
      Returns:
        if successful, a valid buffered image
      Throws:
        `ImageReadException` - in the event of a processing error while reading an image (i.e. a format violation, etc.).
        `IOException` - in the event of an unrecoverable I/O exception.

    - #### getBufferedImage

          public static BufferedImage getBufferedImage(InputStream is,
                                                       Map<String,Object> params)
                                                throws ImageReadException,
                                                       IOException

      Reads the first image from an InputStream using data-processing options specified through a parameters map. Options may be configured using the ImagingContants interface or the various format-specific implementations provided by this package.

      For the most recent information on support for specific formats, refer to Format Support at the main project development web site. While the Apache Commons Imaging package does not fully support all formats, it can read image info, metadata and ICC profiles from all image formats that provide this data.

      Parameters:
        `is` - a valid ImageStream from which to read data.
        `params` - an optional parameters map specifying options
      Returns:
        if successful, a valid buffered image
      Throws:
        `ImageReadException` - in the event of a processing error while reading an image (i.e. a format violation, etc.).
        `IOException` - in the event of an unrecoverable I/O exception.

    - #### getBufferedImage

          public static BufferedImage getBufferedImage(byte[] bytes)
                                                throws ImageReadException,
                                                       IOException

      Reads the first image from a byte array.

      For the most recent information on support for specific formats, refer to Format Support at the main project development web site. While the Apache Commons Imaging package does not fully support all formats, it can read image info, metadata and ICC profiles from all image formats that provide this data.

      Parameters:
        `bytes` - a valid array of bytes from which to read data.
      Returns:
        if successful, a valid buffered image
      Throws:
        `ImageReadException` - in the event of a processing error while reading an image (i.e. a format violation, etc.).
        `IOException` - in the event of an unrecoverable I/O exception.

    - #### getBufferedImage

          public static BufferedImage getBufferedImage(byte[] bytes,
                                                       Map<String,Object> params)
                                                throws ImageReadException,
                                                       IOException

      Reads the first image from a byte array using data-processing options specified through a parameters map. Options may be configured using the ImagingContants interface or the various format-specific implementations provided by this package.

      For the most recent information on support for specific formats, refer to Format Support at the main project development web site. While the Apache Commons Imaging package does not fully support all formats, it can read image info, metadata and ICC profiles from all image formats that provide this data.

      Parameters:
        `bytes` - a valid array of bytes from which to read data.
        `params` - an optional parameters map specifying options.
      Returns:
        if successful, a valid buffered image
      Throws:
        `ImageReadException` - in the event of a processing error while reading an image (i.e. a format violation, etc.).
        `IOException` - in the event of an unrecoverable I/O exception.

    - #### getBufferedImage

          public static BufferedImage getBufferedImage(File file)
                                                throws ImageReadException,
                                                       IOException

      Reads the first image from a file.

      For the most recent information on support for specific formats, refer to Format Support at the main project development web site. While the Apache Commons Imaging package does not fully support all formats, it can read image info, metadata and ICC profiles from all image formats that provide this data.

      Parameters:
        `file` - a valid reference to a file containing image data.
      Returns:
        if successful, a valid buffered image
      Throws:
        `ImageReadException` - in the event of a processing error while reading an image (i.e. a format violation, etc.).
        `IOException` - in the event of an unrecoverable I/O exception.

    - #### getBufferedImage

          public static BufferedImage getBufferedImage(File file,
                                                       Map<String,Object> params)
                                                throws ImageReadException,
                                                       IOException

      Reads the first image from a file using data-processing options specified through a parameters map. Options may be configured using the ImagingContants interface or the various format-specific implementations provided by this package.

      For the most recent information on support for specific formats, refer to Format Support at the main project development web site. While the Apache Commons Imaging package does not fully support all formats, it can read image info, metadata and ICC profiles from all image formats that provide this data.

      Parameters:
        `file` - a valid reference to a file containing image data.
        `params` - parameters map.
      Returns:
        if successful, a valid buffered image
      Throws:
        `ImageReadException` - in the event of a processing error while reading an image (i.e. a format violation, etc.).
        `IOException` - in the event of an unrecoverable I/O exception.

    - #### writeImage

          public static void writeImage(BufferedImage src,
                                        File file,
                                        ImageFormat format,
                                        Map<String,Object> params)
                                 throws ImageWriteException,
                                        IOException

      Writes the content of a BufferedImage to a file using the specified image format. Specifications for storing the file (such as data compression, color models, metadata tags, etc.) may be specified using an optional parameters map. These specifications are defined in the ImagingConstants interface or in various format-specific implementations.

      Image writing is not supported for all graphics formats. For the most recent information on support for specific formats, refer to Format Support at the main project development web site. While the Apache Commons Imaging package does not fully support all formats, it can read image info, metadata and ICC profiles from all image formats that provide this data.

      Parameters:
        `src` - a valid BufferedImage object
        `file` - the file to which the output image is to be written
        `format` - the format in which the output image is to be written
        `params` - an optional parameters map (nulls permitted)
      Throws:
        `ImageWriteException` - in the event of a format violation, unsupported image format, etc.
        `IOException` - in the event of an unrecoverable I/O exception.
      See Also:
        `ImagingConstants`

    - #### writeImageToBytes

          public static byte[] writeImageToBytes(BufferedImage src,
                                                 ImageFormat format,
                                                 Map<String,Object> params)
                                          throws ImageWriteException,
                                                 IOException

      Writes the content of a BufferedImage to a byte array using the specified image format. Specifications for storing the file (such as data compression, color models, metadata tags, etc.) may be specified using an optional parameters map. These specifications are defined in the ImagingConstants interface or in various format-specific implementations.

      Image writing is not supported for all graphics formats. For the most recent information on support for specific formats, refer to Format Support at the main project development web site. While the Apache Commons Imaging package does not fully support all formats, it can read image info, metadata and ICC profiles from all image formats that provide this data.

      Parameters:
        `src` - a valid BufferedImage object
        `format` - the format in which the output image is to be written
        `params` - an optional parameters map (nulls permitted)
      Returns:
        if successful, a valid array of bytes.
      Throws:
        `ImageWriteException` - in the event of a format violation, unsupported image format, etc.
        `IOException` - in the event of an unrecoverable I/O exception.
      See Also:
        `ImagingConstants`

    - #### writeImage

          public static void writeImage(BufferedImage src,
                                        OutputStream os,
                                        ImageFormat format,
                                        Map<String,Object> params)
                                 throws ImageWriteException,
                                        IOException

      Writes the content of a BufferedImage to an OutputStream using the specified image format. Specifications for storing the file (such as data compression, color models, metadata tags, etc.) may be specified using an optional parameters map. These specifications are defined in the ImagingConstants interface or in various format-specific implementations.

      Image writing is not supported for all graphics formats. For the most recent information on support for specific formats, refer to Format Support at the main project development web site. While the Apache Commons Imaging package does not fully support all formats, it can read image info, metadata and ICC profiles from all image formats that provide this data.

      Parameters:
        `src` - a valid BufferedImage object
        `os` - the OutputStream to which the output image is to be written
        `format` - the format in which the output image is to be written
        `params` - an optional parameters map (nulls permitted)
      Throws:
        `ImageWriteException` - in the event of a format violation, unsupported image format, etc.
        `IOException` - in the event of an unrecoverable I/O exception.
      See Also:
        `ImagingConstants`

Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.