Class ImageExtensions


  • public class ImageExtensions
    extends java.lang.Object
    The class ImageExtensions.
    • Constructor Summary

      Constructors 
      Constructor Description
      ImageExtensions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.image.BufferedImage concatenateImages​(java.util.List<java.awt.image.BufferedImage> imgCollection, int width, int height, int imageType, Direction concatenationDirection)
      Concatenate the given list of BufferedImage objects to one image and returns the concatenated BufferedImage object.
      static void createPdf​(java.io.OutputStream result, java.util.List<java.awt.image.BufferedImage> images)
      Creates from the given Collection of images an pdf file.
      static java.awt.image.BufferedImage getResized​(java.awt.image.BufferedImage originalImage, java.lang.String formatName, int targetWidth, int targetHeight)
      Resize the given BufferedImage and returns the resized BufferedImage.
      static java.awt.image.BufferedImage getResized​(java.awt.image.BufferedImage originalImage, org.imgscalr.Scalr.Method scalingMethod, org.imgscalr.Scalr.Mode resizeMode, java.lang.String formatName, int targetWidth, int targetHeight)
      Resize the given BufferedImage and returns the resized BufferedImage.
      static javax.swing.ImageIcon newImageIcon​(java.io.File image)
      Factory method for create a new ImageIcon.
      static com.itextpdf.text.pdf.PdfPTable newPdfPTable​(int numColumns, java.util.List<java.lang.String> headerNames)
      Factory method for create a new PdfPTable with the given count of columns and the column header names
      static java.awt.image.BufferedImage randomBufferedImage​(int width, int height, int imageType)
      Generates a random BufferedImage with the given parameters.
      static java.awt.image.BufferedImage read​(byte[] byteArray)
      Gets the buffered image from the given byte array.
      static java.awt.image.BufferedImage readQuietly​(byte[] byteArray)
      Gets the buffered image from the given byte array quietly.
      static java.awt.image.BufferedImage readQuietly​(java.io.InputStream input)
      Gets the buffered image from the given byte array quietly.
      static byte[] resize​(java.awt.image.BufferedImage originalImage, java.lang.String formatName, int targetWidth, int targetHeight)
      Resize the given BufferedImage.
      static byte[] resize​(java.awt.image.BufferedImage originalImage, org.imgscalr.Scalr.Method scalingMethod, org.imgscalr.Scalr.Mode resizeMode, java.lang.String formatName, int targetWidth, int targetHeight)
      Resize the given image.
      static byte[] toByteArray​(java.awt.image.BufferedImage bi, java.lang.String formatName)
      Converts the given BufferedImage to a byte array.
      static java.lang.String unweaveFrom​(java.awt.image.BufferedImage bufferedImage)
      Unweave a secret message from the given BufferedImage.
      static java.awt.image.BufferedImage weaveInto​(java.awt.image.BufferedImage bufferedImage, java.lang.String message)
      Weave the given secret message into the given BufferedImage.
      static java.io.File write​(java.awt.image.BufferedImage bufferedImage, java.lang.String formatName, java.io.File outputfile)
      Convenience method to write the given BufferedImage object to the given File object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ImageExtensions

        public ImageExtensions()
    • Method Detail

      • concatenateImages

        public static java.awt.image.BufferedImage concatenateImages​(java.util.List<java.awt.image.BufferedImage> imgCollection,
                                                                     int width,
                                                                     int height,
                                                                     int imageType,
                                                                     Direction concatenationDirection)
        Concatenate the given list of BufferedImage objects to one image and returns the concatenated BufferedImage object.
        Parameters:
        imgCollection - the BufferedImage collection
        width - the width of the image that will be returned.
        height - the height of the image that will be returned.
        imageType - type of the created image
        concatenationDirection - the direction of the concatenation.
        Returns:
        the buffered image
      • createPdf

        public static void createPdf​(java.io.OutputStream result,
                                     java.util.List<java.awt.image.BufferedImage> images)
                              throws com.itextpdf.text.DocumentException,
                                     java.io.IOException
        Creates from the given Collection of images an pdf file.
        Parameters:
        result - the output stream from the pdf file where the images shell be written.
        images - the BufferedImage collection to be written in the pdf file.
        Throws:
        com.itextpdf.text.DocumentException - is thrown if an error occurs when trying to get an instance of PdfWriter.
        java.io.IOException - Signals that an I/O exception has occurred.
      • getResized

        public static java.awt.image.BufferedImage getResized​(java.awt.image.BufferedImage originalImage,
                                                              org.imgscalr.Scalr.Method scalingMethod,
                                                              org.imgscalr.Scalr.Mode resizeMode,
                                                              java.lang.String formatName,
                                                              int targetWidth,
                                                              int targetHeight)
                                                       throws java.io.IOException
        Resize the given BufferedImage and returns the resized BufferedImage.
        Parameters:
        originalImage - the original image
        scalingMethod - the scaling method
        resizeMode - the resize mode
        formatName - the format name
        targetWidth - the target width
        targetHeight - the target height
        Returns:
        the resized
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • getResized

        public static java.awt.image.BufferedImage getResized​(java.awt.image.BufferedImage originalImage,
                                                              java.lang.String formatName,
                                                              int targetWidth,
                                                              int targetHeight)
                                                       throws java.io.IOException
        Resize the given BufferedImage and returns the resized BufferedImage.
        Parameters:
        originalImage - the original image
        formatName - the format name
        targetWidth - the target width
        targetHeight - the target height
        Returns:
        the resized
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newImageIcon

        public static javax.swing.ImageIcon newImageIcon​(java.io.File image)
        Factory method for create a new ImageIcon.
        Parameters:
        image - the file that contains the image
        Returns:
        the new ImageIcon
      • newPdfPTable

        public static com.itextpdf.text.pdf.PdfPTable newPdfPTable​(int numColumns,
                                                                   java.util.List<java.lang.String> headerNames)
        Factory method for create a new PdfPTable with the given count of columns and the column header names
        Parameters:
        numColumns - the count of columns of the table
        headerNames - the column header names
        Returns:
        the new PdfPTable
      • randomBufferedImage

        public static java.awt.image.BufferedImage randomBufferedImage​(int width,
                                                                       int height,
                                                                       int imageType)
        Generates a random BufferedImage with the given parameters.
        Parameters:
        width - the width
        height - the height
        imageType - the type of the image
        Returns:
        The generated BufferedImage.
      • read

        public static java.awt.image.BufferedImage read​(byte[] byteArray)
                                                 throws java.io.IOException
        Gets the buffered image from the given byte array.
        Parameters:
        byteArray - the byte array
        Returns:
        the buffered image
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • readQuietly

        public static java.awt.image.BufferedImage readQuietly​(byte[] byteArray)
        Gets the buffered image from the given byte array quietly.
        Parameters:
        byteArray - the byte array
        Returns:
        the buffered image or null if the read process failed.
      • readQuietly

        public static java.awt.image.BufferedImage readQuietly​(java.io.InputStream input)
        Gets the buffered image from the given byte array quietly.
        Parameters:
        input - the input
        Returns:
        the buffered image or null if the read process failed.
      • resize

        public static byte[] resize​(java.awt.image.BufferedImage originalImage,
                                    org.imgscalr.Scalr.Method scalingMethod,
                                    org.imgscalr.Scalr.Mode resizeMode,
                                    java.lang.String formatName,
                                    int targetWidth,
                                    int targetHeight)
        Resize the given image.
        Parameters:
        originalImage - the original image
        scalingMethod - the scaling method
        resizeMode - the resize mode
        formatName - the format name
        targetWidth - the target width
        targetHeight - the target height
        Returns:
        the byte[]
      • resize

        public static byte[] resize​(java.awt.image.BufferedImage originalImage,
                                    java.lang.String formatName,
                                    int targetWidth,
                                    int targetHeight)
        Resize the given BufferedImage.
        Parameters:
        originalImage - the original image
        formatName - the format name
        targetWidth - the target width
        targetHeight - the target height
        Returns:
        the byte[]
      • toByteArray

        public static byte[] toByteArray​(java.awt.image.BufferedImage bi,
                                         java.lang.String formatName)
                                  throws java.io.IOException
        Converts the given BufferedImage to a byte array.
        Parameters:
        bi - the bi
        formatName - the format name
        Returns:
        the byte[]
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • unweaveFrom

        public static java.lang.String unweaveFrom​(java.awt.image.BufferedImage bufferedImage)
        Unweave a secret message from the given BufferedImage.
        Parameters:
        bufferedImage - the buffered image
        Returns:
        the secret message
      • weaveInto

        public static java.awt.image.BufferedImage weaveInto​(java.awt.image.BufferedImage bufferedImage,
                                                             java.lang.String message)
        Weave the given secret message into the given BufferedImage.
        Parameters:
        bufferedImage - the buffered image
        message - the secret message
        Returns:
        the buffered image with the secret message weaved in.
      • write

        public static java.io.File write​(java.awt.image.BufferedImage bufferedImage,
                                         java.lang.String formatName,
                                         java.io.File outputfile)
                                  throws java.io.IOException
        Convenience method to write the given BufferedImage object to the given File object.
        Parameters:
        bufferedImage - the BufferedImage object to be written.
        formatName - the format name
        outputfile - the output file
        Returns:
        the file
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.