Package io.github.connellite.image
Class ImageHelper
java.lang.Object
io.github.connellite.image.ImageHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageClones an image.static BufferedImageA simple method to convert an image to binary or B/W image.static BufferedImageA simple method to convert an image to gray scale.static BufferedImagecreateBufferedImage(int width, int height, BufferedImage image) Create a new buffered image with the same characteristics (color model, raster type, properties...) than the specified one.static voiddrawImg(BufferedImage image, File file) static doublegetSimilarImage(BufferedImage bufImg1, BufferedImage bufImg2) Returns the percentage of identical pixels between two images of the same width and height.static BufferedImageinvertImageColor(BufferedImage image) Inverts image color.static BufferedImageReads aBufferedImagefrom the given file.static BufferedImageremoveAlphaChannel(BufferedImage image) Removes alpha channel from imagestatic BufferedImagerotateImage(BufferedImage image, double angle) Rotates an image.
-
Constructor Details
-
ImageHelper
public ImageHelper()
-
-
Method Details
-
readImage
Reads aBufferedImagefrom the given file.- Parameters:
file- image file- Returns:
- loaded image, or
nullif no suitable reader is found - Throws:
IOException- if an error occurs during reading
-
getSimilarImage
Returns the percentage of identical pixels between two images of the same width and height. If dimensions differ, returns0.0.- Parameters:
bufImg1- first imagebufImg2- second image- Returns:
- similarity in percent (
0.0–100.0), or0.0when sizes differ
-
convertImageToBinary
A simple method to convert an image to binary or B/W image.- Parameters:
image- input image- Returns:
- a monochrome image
-
removeAlphaChannel
Removes alpha channel from image- Parameters:
image- input image- Returns:
- image with alpha channel removed
-
convertImageToGrayscale
A simple method to convert an image to gray scale.- Parameters:
image- input image- Returns:
- a monochrome image
-
invertImageColor
Inverts image color.- Parameters:
image- input image- Returns:
- an inverted-color image
-
rotateImage
Rotates an image.- Parameters:
image- the original imageangle- the degree of rotation- Returns:
- a rotated image
-
cloneImage
Clones an image. Clones an image- Parameters:
bi- input image- Returns:
- cloned image
-
createBufferedImage
Create a new buffered image with the same characteristics (color model, raster type, properties...) than the specified one.- Parameters:
width- the widthheight- the heightimage- an image with the same characteristics than the one which will be created.
-
drawImg
Writesimagetofileusing anImageWriterchosen from the file extension. When the writer supports compression, uses explicit mode with quality0.1. Does nothing if the extension is missing, no writer is found, or an image output stream cannot be created.- Parameters:
image- image to writefile- destination file (format is inferred from the filename extension)- Throws:
IOException- if an error occurs during writing
-