Class ImageHelper

java.lang.Object
io.github.connellite.image.ImageHelper

public class ImageHelper extends Object
  • Constructor Details

    • ImageHelper

      public ImageHelper()
  • Method Details

    • readImage

      public static BufferedImage readImage(File file) throws IOException
      Reads a BufferedImage from the given file.
      Parameters:
      file - image file
      Returns:
      loaded image, or null if no suitable reader is found
      Throws:
      IOException - if an error occurs during reading
    • getSimilarImage

      public static double getSimilarImage(BufferedImage bufImg1, BufferedImage bufImg2)
      Returns the percentage of identical pixels between two images of the same width and height. If dimensions differ, returns 0.0.
      Parameters:
      bufImg1 - first image
      bufImg2 - second image
      Returns:
      similarity in percent (0.0–100.0), or 0.0 when sizes differ
    • convertImageToBinary

      public static BufferedImage convertImageToBinary(BufferedImage image)
      A simple method to convert an image to binary or B/W image.
      Parameters:
      image - input image
      Returns:
      a monochrome image
    • removeAlphaChannel

      public static BufferedImage removeAlphaChannel(BufferedImage image)
      Removes alpha channel from image
      Parameters:
      image - input image
      Returns:
      image with alpha channel removed
    • convertImageToGrayscale

      public static BufferedImage convertImageToGrayscale(BufferedImage image)
      A simple method to convert an image to gray scale.
      Parameters:
      image - input image
      Returns:
      a monochrome image
    • invertImageColor

      public static BufferedImage invertImageColor(BufferedImage image)
      Inverts image color.
      Parameters:
      image - input image
      Returns:
      an inverted-color image
    • rotateImage

      public static BufferedImage rotateImage(BufferedImage image, double angle)
      Rotates an image.
      Parameters:
      image - the original image
      angle - the degree of rotation
      Returns:
      a rotated image
    • cloneImage

      public static BufferedImage cloneImage(BufferedImage bi)
      Clones an image. Clones an image
      Parameters:
      bi - input image
      Returns:
      cloned image
    • createBufferedImage

      public static BufferedImage createBufferedImage(int width, int height, BufferedImage image)
      Create a new buffered image with the same characteristics (color model, raster type, properties...) than the specified one.
      Parameters:
      width - the width
      height - the height
      image - an image with the same characteristics than the one which will be created.
    • drawImg

      public static void drawImg(BufferedImage image, File file) throws IOException
      Writes image to file using an ImageWriter chosen from the file extension. When the writer supports compression, uses explicit mode with quality 0.1. Does nothing if the extension is missing, no writer is found, or an image output stream cannot be created.
      Parameters:
      image - image to write
      file - destination file (format is inferred from the filename extension)
      Throws:
      IOException - if an error occurs during writing