Class ImageData

java.lang.Object
com.itextpdf.io.image.ImageData
Direct Known Subclasses:
Jbig2ImageData, Jpeg2000ImageData, JpegImageData, RawImageData, WebPImageData, WmfImageData

public abstract class ImageData extends Object
Describes encoded image data and the attributes needed to embed it in a document.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    bpc
    Bits per color component.
    protected int
    Is the number of components used to encode colorspace.
    protected int
    Color-transform selector used by formats that support it.
    protected byte[]
    Encoded image bytes, or null until data is loaded from url.
    protected float[]
    Decode array applied to image samples, or null when no decode array is specified.
    protected Map<String,Object>
    Parameters associated with the image decoder, or null.
    protected boolean
    Whether data is already deflate-compressed.
    protected int
    Horizontal resolution in dots per inch, or 0 when unspecified.
    protected int
    Vertical resolution in dots per inch, or 0 when unspecified.
    protected String
    PDF filter name used to decode the image data, or null.
    protected float
    Image height in pixels.
    protected Map<String,Object>
    Additional image attributes, or null.
    protected ImageData
    Mask image associated with this image, or null.
    protected int
    Size of the image data in bytes when known.
    protected boolean
    Whether interpolation should be requested when rendering the image.
    protected boolean
    Whether the image samples are inverted.
    protected boolean
    Whether this image is used as an image mask.
    protected Long
    Deprecated.
    protected ImageType
    Detected or declared format of the source image.
    protected IccProfile
    ICC color profile associated with the image, or null.
    protected float
    Clockwise rotation to apply to the image, in degrees.
    protected int[]
    Component-value pairs defining transparent ranges, or null when no range is specified.
    protected URL
    url
    Source URL from which the image bytes can be loaded, or null when bytes were supplied directly.
    protected float
    Image width in pixels.
    protected float
    Pixel aspect ratio, or 0 when unspecified.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    ImageData(byte[] bytes, ImageType type)
    Creates image data from encoded bytes.
    protected
    ImageData(URL url, ImageType type)
    Creates image data whose bytes are available from a URL.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks whether this image can be converted to an image mask.
    boolean
    Checks if image can be inline
    int
    getBpc()
    Gets the number of bits used for each color component.
    int
    Gets the number of components used to encode colorspace.
    int
    Gets the color-transform selector.
    byte[]
    Gets the encoded image bytes.
    float[]
    Gets the image decode array.
    Gets image decoder parameters.
    int
    Gets the horizontal image resolution.
    int
    Gets the vertical image resolution.
    Gets the PDF filter name used for the image data.
    float
    Gets the image height.
    Gets additional image attributes.
    Gets the mask image associated with this image.
    Gets the source image format.
    Gets the associated ICC color profile.
    float
    Gets the clockwise rotation applied to the image.
    int[]
    Gets the component-value pairs that define transparent ranges.
    URL
    getUrl()
    Gets the source URL.
    float
    Gets the image width.
    float
    Gets the pixel aspect ratio.
    boolean
    Checks whether image bytes are already deflate-compressed.
    boolean
    Checks whether interpolation should be requested while rendering.
    boolean
    Checks whether image samples are inverted.
    boolean
    isMask()
    Checks whether this image is an image mask.
    boolean
    Indicates whether this instance represents raw sample data.
    boolean
    Checks whether this image is a soft mask.
    protected void
    Load data from URL.
    void
    Converts this image to an image mask.
    void
    setBpc(int bpc)
    Sets the number of bits used for each color component.
    void
    setColorEncodingComponentsNumber(int colorEncodingComponentsNumber)
    Sets the number of components used to encode colorspace.
    void
    setColorTransform(int colorTransform)
    Sets the color-transform selector.
    void
    setDecode(float[] decode)
    Sets the image decode array.
    void
    setDeflated(boolean deflated)
    Sets whether image bytes are already deflate-compressed.
    void
    setDpi(int dpiX, int dpiY)
    Sets the image resolution.
    void
    setFilter(String filter)
    Sets the PDF filter name used for the image data.
    void
    setHeight(float height)
    Sets the image height.
    void
    setImageAttributes(Map<String,Object> imageAttributes)
    Sets additional image attributes.
    void
    setImageMask(ImageData imageMask)
    Associates a mask image with this image.
    void
    setInterpolation(boolean interpolation)
    Sets whether interpolation should be requested while rendering.
    void
    setInverted(boolean inverted)
    Sets whether image samples are inverted.
    void
    Sets the associated ICC color profile.
    void
    setRotation(float rotation)
    Sets the clockwise rotation applied to the image.
    void
    setTransparency(int[] transparency)
    Sets component-value pairs that define transparent ranges.
    void
    setUrl(URL url)
    Sets the source URL used to load image bytes.
    void
    setWidth(float width)
    Sets the image width.
    void
    setXYRatio(float XYRatio)
    Sets the pixel aspect ratio.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • url

      protected URL url
      Source URL from which the image bytes can be loaded, or null when bytes were supplied directly.
    • transparency

      protected int[] transparency
      Component-value pairs defining transparent ranges, or null when no range is specified.
    • originalType

      protected ImageType originalType
      Detected or declared format of the source image.
    • width

      protected float width
      Image width in pixels.
    • height

      protected float height
      Image height in pixels.
    • data

      protected byte[] data
      Encoded image bytes, or null until data is loaded from url.
    • imageSize

      protected int imageSize
      Size of the image data in bytes when known.
    • bpc

      protected int bpc
      Bits per color component.
    • colorEncodingComponentsNumber

      protected int colorEncodingComponentsNumber
      Is the number of components used to encode colorspace.
    • decode

      protected float[] decode
      Decode array applied to image samples, or null when no decode array is specified.
    • decodeParms

      protected Map<String,Object> decodeParms
      Parameters associated with the image decoder, or null.
    • inverted

      protected boolean inverted
      Whether the image samples are inverted.
    • rotation

      protected float rotation
      Clockwise rotation to apply to the image, in degrees.
    • profile

      protected IccProfile profile
      ICC color profile associated with the image, or null.
    • dpiX

      protected int dpiX
      Horizontal resolution in dots per inch, or 0 when unspecified.
    • dpiY

      protected int dpiY
      Vertical resolution in dots per inch, or 0 when unspecified.
    • colorTransform

      protected int colorTransform
      Color-transform selector used by formats that support it.
    • deflated

      protected boolean deflated
      Whether data is already deflate-compressed.
    • mask

      protected boolean mask
      Whether this image is used as an image mask.
    • imageMask

      protected ImageData imageMask
      Mask image associated with this image, or null.
    • interpolation

      protected boolean interpolation
      Whether interpolation should be requested when rendering the image.
    • XYRatio

      protected float XYRatio
      Pixel aspect ratio, or 0 when unspecified.
    • filter

      protected String filter
      PDF filter name used to decode the image data, or null.
    • imageAttributes

      protected Map<String,Object> imageAttributes
      Additional image attributes, or null.
    • mySerialId

      @Deprecated protected Long mySerialId
      Deprecated.
  • Constructor Details

    • ImageData

      protected ImageData (URL url, ImageType type)
      Creates image data whose bytes are available from a URL.
      Parameters:
      url - source URL, not null
      type - source image format
    • ImageData

      protected ImageData (byte[] bytes, ImageType type)
      Creates image data from encoded bytes.
      Parameters:
      bytes - encoded image bytes; the array is retained
      type - source image format
  • Method Details

    • isRawImage

      public boolean isRawImage()
      Indicates whether this instance represents raw sample data.
      Returns:
      true for raw image data; false otherwise
    • getUrl

      public URL getUrl()
      Gets the source URL.
      Returns:
      source URL, or null when the image was created from bytes
    • setUrl

      public void setUrl (URL url)
      Sets the source URL used to load image bytes.
      Parameters:
      url - source URL, or null
    • getTransparency

      public int[] getTransparency()
      Gets the component-value pairs that define transparent ranges.
      Returns:
      retained transparency array, or null
    • setTransparency

      public void setTransparency (int[] transparency)
      Sets component-value pairs that define transparent ranges.
      Parameters:
      transparency - transparency array to retain, or null
    • isInverted

      public boolean isInverted()
      Checks whether image samples are inverted.
      Returns:
      true if samples are inverted
    • setInverted

      public void setInverted (boolean inverted)
      Sets whether image samples are inverted.
      Parameters:
      inverted - true to invert samples
    • getRotation

      public float getRotation()
      Gets the clockwise rotation applied to the image.
      Returns:
      rotation in degrees
    • setRotation

      public void setRotation (float rotation)
      Sets the clockwise rotation applied to the image.
      Parameters:
      rotation - rotation in degrees
    • getProfile

      public IccProfile getProfile()
      Gets the associated ICC color profile.
      Returns:
      ICC profile, or null
    • setProfile

      public void setProfile (IccProfile profile)
      Sets the associated ICC color profile.
      Parameters:
      profile - ICC profile to associate, or null
    • getDpiX

      public int getDpiX()
      Gets the horizontal image resolution.
      Returns:
      dots per inch, or 0 when unspecified
    • getDpiY

      public int getDpiY()
      Gets the vertical image resolution.
      Returns:
      dots per inch, or 0 when unspecified
    • setDpi

      public void setDpi (int dpiX, int dpiY)
      Sets the image resolution.
      Parameters:
      dpiX - horizontal resolution in dots per inch
      dpiY - vertical resolution in dots per inch
    • getColorTransform

      public int getColorTransform()
      Gets the color-transform selector.
      Returns:
      color-transform selector
    • setColorTransform

      public void setColorTransform (int colorTransform)
      Sets the color-transform selector.
      Parameters:
      colorTransform - color-transform selector
    • isDeflated

      public boolean isDeflated()
      Checks whether image bytes are already deflate-compressed.
      Returns:
      true when the image bytes are deflated
    • setDeflated

      public void setDeflated (boolean deflated)
      Sets whether image bytes are already deflate-compressed.
      Parameters:
      deflated - true when the image bytes are deflated
    • getOriginalType

      public ImageType getOriginalType()
      Gets the source image format.
      Returns:
      source image format
    • getColorEncodingComponentsNumber

      public int getColorEncodingComponentsNumber()
      Gets the number of components used to encode colorspace.
      Returns:
      the number of components used to encode colorspace
    • setColorEncodingComponentsNumber

      public void setColorEncodingComponentsNumber (int colorEncodingComponentsNumber)
      Sets the number of components used to encode colorspace.
      Parameters:
      colorEncodingComponentsNumber - the number of components used to encode colorspace
    • getData

      public byte[] getData()
      Gets the encoded image bytes.
      Returns:
      retained encoded bytes, or null until loaded
    • canBeMask

      public boolean canBeMask()
      Checks whether this image can be converted to an image mask.
      Returns:
      true if the color encoding permits masking
    • isMask

      public boolean isMask()
      Checks whether this image is an image mask.
      Returns:
      true if this image is a mask
    • getImageMask

      public ImageData getImageMask()
      Gets the mask image associated with this image.
      Returns:
      mask image, or null
    • setImageMask

      public void setImageMask (ImageData imageMask)
      Associates a mask image with this image.
      Parameters:
      imageMask - image that has been made a mask
      Throws:
      IOException - if this image is a mask or imageMask is not a mask
    • isSoftMask

      public boolean isSoftMask()
      Checks whether this image is a soft mask.
      Returns:
      true if this image is a soft mask
    • makeMask

      public void makeMask()
      Converts this image to an image mask.
      Throws:
      IOException - if this image cannot be used as a mask
    • getWidth

      public float getWidth()
      Gets the image width.
      Returns:
      width in pixels
    • setWidth

      public void setWidth (float width)
      Sets the image width.
      Parameters:
      width - width in pixels
    • getHeight

      public float getHeight()
      Gets the image height.
      Returns:
      height in pixels
    • setHeight

      public void setHeight (float height)
      Sets the image height.
      Parameters:
      height - height in pixels
    • getBpc

      public int getBpc()
      Gets the number of bits used for each color component.
      Returns:
      bits per component
    • setBpc

      public void setBpc (int bpc)
      Sets the number of bits used for each color component.
      Parameters:
      bpc - bits per component
    • isInterpolation

      public boolean isInterpolation()
      Checks whether interpolation should be requested while rendering.
      Returns:
      true to request interpolation
    • setInterpolation

      public void setInterpolation (boolean interpolation)
      Sets whether interpolation should be requested while rendering.
      Parameters:
      interpolation - true to request interpolation
    • getXYRatio

      public float getXYRatio()
      Gets the pixel aspect ratio.
      Returns:
      pixel aspect ratio, or 0 when unspecified
    • setXYRatio

      public void setXYRatio (float XYRatio)
      Sets the pixel aspect ratio.
      Parameters:
      XYRatio - pixel aspect ratio
    • getImageAttributes

      public Map<String,Object> getImageAttributes()
      Gets additional image attributes.
      Returns:
      retained attribute map, or null
    • setImageAttributes

      public void setImageAttributes (Map<String,Object> imageAttributes)
      Sets additional image attributes.
      Parameters:
      imageAttributes - attribute map to retain, or null
    • getFilter

      public String getFilter()
      Gets the PDF filter name used for the image data.
      Returns:
      filter name, or null
    • setFilter

      public void setFilter (String filter)
      Sets the PDF filter name used for the image data.
      Parameters:
      filter - PDF filter name, or null
    • getDecodeParms

      public Map<String,Object> getDecodeParms()
      Gets image decoder parameters.
      Returns:
      retained decoder-parameter map, or null
    • getDecode

      public float[] getDecode()
      Gets the image decode array.
      Returns:
      retained decode array, or null
    • setDecode

      public void setDecode (float[] decode)
      Sets the image decode array.
      Parameters:
      decode - decode array to retain, or null
    • canImageBeInline

      public boolean canImageBeInline()
      Checks if image can be inline
      Returns:
      if the image can be inline
    • loadData

      protected void loadData() throws IOException
      Load data from URL. url must be not null. Note, this method doesn't check if data or url is null.
      Throws:
      IOException - if an I/O error occurs.