Class ImageDataFactory

java.lang.Object
com.itextpdf.io.image.ImageDataFactory

public final class ImageDataFactory extends Object
  • Method Details

    • create

      public static ImageData create (byte[] bytes, boolean recoverImage)
      Create an ImageData instance representing the image from the image bytes.
      Parameters:
      bytes - byte representation of the image.
      recoverImage - whether to recover from a image error (for TIFF-images)
      Returns:
      The created ImageData object.
    • create

      public static ImageData create (byte[] bytes)
      Create an ImageData instance representing the image from the image bytes.
      Parameters:
      bytes - byte representation of the image.
      Returns:
      The created ImageData object.
    • create

      public static ImageData create (URL url, boolean recoverImage)
      Create an ImageData instance representing the image from the file located at the specified url.
      Parameters:
      url - location of the image
      recoverImage - whether to recover from a image error (for TIFF-images)
      Returns:
      The created ImageData object.
    • create

      public static ImageData create (URL url)
      Create an ImageData instance representing the image from the file located at the specified url.
      Parameters:
      url - location of the image
      Returns:
      The created ImageData object.
    • create

      public static ImageData create (String filename, boolean recoverImage) throws MalformedURLException
      Create an ImageData instance representing the image from the specified file.
      Parameters:
      filename - filename of the file containing the image
      recoverImage - whether to recover from a image error (for TIFF-images)
      Returns:
      The created ImageData object.
      Throws:
      MalformedURLException - if an error occurred generating the URL.
    • create

      public static ImageData create (String filename) throws MalformedURLException
      Create an ImageData instance representing the image from the specified file.
      Parameters:
      filename - filename of the file containing the image
      Returns:
      The created ImageData object.
      Throws:
      MalformedURLException - if an error occurred generating the URL.
    • create

      public static ImageData create (int width, int height, boolean reverseBits, int typeCCITT, int parameters, byte[] data, int[] transparency)
      Create an ImageData instance from the passed parameters.
      Parameters:
      width - width of the image in pixels
      height - height of the image in pixels
      reverseBits - whether to reverse the bits stored in data (TIFF images).
      typeCCITT - Type of CCITT encoding
      parameters - colour space parameters
      data - array containing raw image data
      transparency - array containing transparency information
      Returns:
      created ImageData object.
    • create

      public static ImageData create (int width, int height, int components, int bpc, byte[] data, int[] transparency)
      Create an ImageData instance from the passed parameters.
      Parameters:
      width - width of the image in pixels
      height - height of the image in pixels
      components - colour space components
      bpc - bits per colour.
      data - array containing raw image data
      transparency - array containing transparency information
      Returns:
      created ImageData object.
    • create

      public static ImageData create (Image image, Color color) throws IOException
      Gets an instance of an Image from a java.awt.Image
      Parameters:
      image - the java.awt.Image to convert
      color - if different from null the transparency pixels are replaced by this color
      Returns:
      RawImage
      Throws:
      IOException - if an I/O error occurs.
    • create

      public static ImageData create (Image image, Color color, boolean forceBW) throws IOException
      Gets an instance of an Image from a java.awt.Image.
      Parameters:
      image - the java.awt.Image to convert
      color - if different from null the transparency pixels are replaced by this color
      forceBW - if true the image is treated as black and white
      Returns:
      RawImage
      Throws:
      IOException - if an I/O error occurs.
    • createBmp

      public static ImageData createBmp (URL url, boolean noHeader)
      Get a bitmap ImageData instance from the specified url.
      Parameters:
      url - location of the image.
      noHeader - Whether the image contains a header.
      Returns:
      created ImageData
    • createBmp

      public static ImageData createBmp (byte[] bytes, boolean noHeader)
      Get a bitmap ImageData instance from the provided bytes.
      Parameters:
      bytes - array containing the raw image data
      noHeader - Whether the image contains a header.
      Returns:
      created ImageData
    • createGif

      public static GifImageData createGif (byte[] bytes)
      Return a GifImage object. This object cannot be added to a document
      Parameters:
      bytes - array containing the raw image data
      Returns:
      GifImageData instance.
    • createGifFrame

      public static ImageData createGifFrame (URL url, int frame)
      Returns a specified frame of the gif image
      Parameters:
      url - url of gif image
      frame - number of frame to be returned, 1-based
      Returns:
      GifImageData instance.
    • createGifFrame

      public static ImageData createGifFrame (byte[] bytes, int frame)
      Returns a specified frame of the gif image
      Parameters:
      bytes - byte array of gif image
      frame - number of frame to be returned, 1-based
      Returns:
      GifImageData instance
    • createGifFrames

      public static List<ImageData> createGifFrames (byte[] bytes, int[] frameNumbers)
      Returns List of gif image frames
      Parameters:
      bytes - byte array of gif image
      frameNumbers - array of frame numbers of gif image, 1-based
      Returns:
      all frames of gif image
    • createGifFrames

      public static List<ImageData> createGifFrames (URL url, int[] frameNumbers)
      Returns List of gif image frames
      Parameters:
      url - url of gif image
      frameNumbers - array of frame numbers of gif image, 1-based
      Returns:
      all frames of gif image
    • createGifFrames

      public static List<ImageData> createGifFrames (byte[] bytes)
      Returns List of gif image frames
      Parameters:
      bytes - byte array of gif image
      Returns:
      all frames of gif image
    • createGifFrames

      public static List<ImageData> createGifFrames (URL url)
      Returns List of gif image frames
      Parameters:
      url - url of gif image
      Returns:
      all frames of gif image
    • createJbig2

      public static ImageData createJbig2 (URL url, int page)
    • createJbig2

      public static ImageData createJbig2 (byte[] bytes, int page)
    • createJpeg

      public static ImageData createJpeg (URL url)
      Create an ImageData instance from a Jpeg image url
      Parameters:
      url - URL
      Returns:
      the created JPEG image
    • createJpeg

      public static ImageData createJpeg (byte[] bytes)
    • createJpeg2000

      public static ImageData createJpeg2000 (URL url)
    • createJpeg2000

      public static ImageData createJpeg2000 (byte[] bytes)
    • createPng

      public static ImageData createPng (URL url)
    • createPng

      public static ImageData createPng (byte[] bytes)
    • createTiff

      public static ImageData createTiff (URL url, boolean recoverFromImageError, int page, boolean direct)
    • createTiff

      public static ImageData createTiff (byte[] bytes, boolean recoverFromImageError, int page, boolean direct)
    • createRawImage

      public static ImageData createRawImage (byte[] bytes)
    • isSupportedType

      public static boolean isSupportedType (byte[] source)
      Checks if the type of image (based on first 8 bytes) is supported by factory.
      Note: if this method returns true it doesn't means that create(byte[]) won't throw exception
      Parameters:
      source - image raw bytes
      Returns:
      true if first eight bytes are recognised by factory as valid image type and false otherwise
    • isSupportedType

      public static boolean isSupportedType (URL source)
      Checks if the type of image (based on first 8 bytes) is supported by factory.
      Note: if this method returns true it doesn't means that create(byte[]) won't throw exception
      Parameters:
      source - image URL
      Returns:
      true if first eight bytes are recognised by factory as valid image type and false otherwise
    • isSupportedType

      public static boolean isSupportedType (ImageType imageType)
      Checks if the type of image is supported by factory.
      Note: if this method returns true it doesn't means that create(byte[]) won't throw exception
      Parameters:
      imageType - image type
      Returns:
      true if image type is supported and false otherwise