Class ImageUtils

java.lang.Object
eu.europa.esig.dss.pdf.visible.ImageUtils

public class ImageUtils extends Object
Static utilities for image creation and processing
Author:
pakeyser
  • Field Details

    • OPAQUE_VALUE

      public static final float OPAQUE_VALUE
      Defines the default value for a non-transparent alpha layer
      See Also:
    • CMYK_PROFILE_NAME

      public static final String CMYK_PROFILE_NAME
      The CMYK color profile
      See Also:
    • RGB_PROFILE_NAME

      public static final String RGB_PROFILE_NAME
      The RGB color profile
      See Also:
    • GRAY_PROFILE_NAME

      public static final String GRAY_PROFILE_NAME
      The GRAY color profile
      See Also:
    • OUTPUT_INTENT_SRGB_PROFILE

      public static final String OUTPUT_INTENT_SRGB_PROFILE
      Defines the sRGB ICC profile name used in OutputIntent
      See Also:
    • DEFAULT_FIRST_PAGE

      public static final int DEFAULT_FIRST_PAGE
      Defines a number of a first page in a document
      See Also:
  • Method Details

    • secureReadMetadata

      public static ImageResolution secureReadMetadata(SignatureImageParameters imageParameters) throws IOException
      Reads image's metadata in a secure way. If metadata is not accessible from image, returns values from imageParameters
      Parameters:
      imageParameters - SignatureImageParameters
      Returns:
      ImageResolution metadata
      Throws:
      IOException - in case of image reading error
    • readDisplayMetadata

      public static ImageResolution readDisplayMetadata(DSSDocument image) throws IOException
      Reads image's metadata
      Parameters:
      image - DSSDocument image to read metadata from
      Returns:
      ImageResolution metadata
      Throws:
      IOException - in case of image reading error
    • getImageBoundaryBox

      public static AnnotationBox getImageBoundaryBox(DSSDocument imageDocument)
      Returns the AnnotationBox for the given image document
      Parameters:
      imageDocument - DSSDocument representing an image
      Returns:
      AnnotationBox
    • getScaleFactor

      public static float getScaleFactor(int zoom)
      Returns a coefficient applying to a signature field width/height calculation
      Parameters:
      zoom - - zoom value to compute scale factor from
      Returns:
      float scale factor
    • toDSSDocument

      public static DSSDocument toDSSDocument(BufferedImage bufferedImage)
      Transforms a BufferedImage to DSSDocument using in memory processing
      Parameters:
      bufferedImage - BufferedImage to convert
      Returns:
      DSSDocument
    • toDSSDocument

      public static DSSDocument toDSSDocument(BufferedImage bufferedImage, DSSResourcesHandler dssResourcesHandler)
      Transforms a BufferedImage to DSSDocument, using a provided DSSResourcesHandler
      Parameters:
      bufferedImage - BufferedImage to convert
      dssResourcesHandler - DSSResourcesHandler
      Returns:
      DSSDocument
    • toBufferedImage

      public static BufferedImage toBufferedImage(DSSDocument imageDocument) throws IOException
      Reads the image document and returns a BufferedImage
      Parameters:
      imageDocument - DSSDocument image document to read
      Returns:
      BufferedImage
      Throws:
      IOException - - in case of InputStream reading error
    • toBufferedImage

      public static BufferedImage toBufferedImage(InputStream is) throws IOException
      Reads image from InputStream. Detects and converts CMYK images to RGB if needed
      Parameters:
      is - InputStream to read the image from
      Returns:
      BufferedImage
      Throws:
      IOException - - in case of InputStream reading error
    • isTransparent

      public static boolean isTransparent(BufferedImage bufferedImage)
      Checks if the image has a transparent layer
      Parameters:
      bufferedImage - BufferedImage
      Returns:
      TRUE if the image has a transparent layer, FALSE otherwise
    • imagesEqual

      public static boolean imagesEqual(BufferedImage img1, BufferedImage img2)
      Checks if the two given images are equal
      Parameters:
      img1 - BufferedImage
      img2 - BufferedImage
      Returns:
      TRUE if the two images are equal, FALSE otherwise
    • imageDimensionsEqual

      public static boolean imageDimensionsEqual(BufferedImage img1, BufferedImage img2)
      Checks if the dimensions of the provided images is equal
      Parameters:
      img1 - BufferedImage
      img2 - BufferedImage
      Returns:
      TRUE if the size dimensions of both images is equal, FALSE otherwise
    • drawSubtractionImage

      public static int drawSubtractionImage(BufferedImage img1, BufferedImage img2, BufferedImage outImg)
      Draws the subtraction image and returns different pixels amount
      Parameters:
      img1 - BufferedImage to compare
      img2 - BufferedImage to compare
      outImg - BufferedImage the output result (subtraction image)
      Returns:
      amount of different pixels between two images
    • isGrayscale

      public static boolean isGrayscale(Color color)
      This method verifies if the provided color lies in the grayscale color space (e.g. WHITE, GRAY, BLACK)
      Parameters:
      color - Color to check
      Returns:
      TRUE if the color is a grayscale, FALSE otherwise
    • containRGBColor

      public static boolean containRGBColor(SignatureImageParameters parameters)
      This method verifies whether the parameters contain at least one RGB color
      Parameters:
      parameters - SignatureImageParameters to check
      Returns:
      TRUE if the given parameters contains at least one RGB color, FALSE otherwise