Package com.logicaldoc.core.imaging
Class ImageUtil
- java.lang.Object
-
- com.logicaldoc.core.imaging.ImageUtil
-
public class ImageUtil extends Object
Utility methods for handling images- Since:
- 8.5.3
- Author:
- Marco Meschieri - LogicalDOC
-
-
Constructor Summary
Constructors Constructor Description ImageUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static BufferedImage
cloneImage(BufferedImage bi)
Clones an image.static BufferedImage
convertImage2Binary(BufferedImage image)
Deprecated.As of release 1.1, renamed toconvertImageToBinary(BufferedImage image)
static BufferedImage
convertImageToBinary(BufferedImage image)
A simple method to convert an image to binary or B/W image.static BufferedImage
convertImageToGrayscale(BufferedImage image)
A simple method to convert an image to gray scale.static BufferedImage
cropCenterSquare(BufferedImage originalImage, int squareSize)
Crops a square at the center of the given imagestatic BufferedImage
cropImage(BufferedImage originalImage, ImageZone zone)
Crops an area from given imagestatic void
cropImageToFile(String content, ImageZone zone, File file)
Crops an area and stores it in a given .jpg filestatic int[]
cropVisibleContent(File src, File dst)
Crops an image leaving the smallest square containing something visiblestatic String
encodeImage(File image)
Encodes in Base64 the given image filestatic Image
getClipboardImage()
Gets an image from Clipboard.static BufferedImage
getScaledInstance(BufferedImage image, int targetWidth, int targetHeight)
Convenience method that returns a scaled instance of the providedBufferedImage
.static IIOImage
getScaledInstance(IIOImage iioSource, float scale)
Convenience method that returns a scaled instance of the providedIIOImage
.static BufferedImage
getSubImage(BufferedImage image, int x, int y, int width, int height)
A replacement for the standardBufferedImage.getSubimage
method.static BufferedImage
invertImageColor(BufferedImage image)
Inverts image color.static boolean
isBlack(BufferedImage image, int x, int y)
Whether the pixel is black.static boolean
isBlack(BufferedImage image, int x, int y, int luminanceCutOff)
Whether the pixel is black.static void
pasteImage(BufferedImage container, BufferedImage imageIn, float opaque, int x, int y)
Prints the contents of imageIn on container the given opaque valuestatic void
printFirstPage(File originalFile, String originalFileName, File out)
Prints the first page of the given file into the output as .jpg imagestatic BufferedImage
rotate(BufferedImage image, double angle, int cx, int cy)
Rotates image.static BufferedImage
rotateImage(BufferedImage image, double angle)
Rotates an image.static void
saveImage(String content, File file)
Saves an image into a given file in an image formatstatic BufferedImage
textToImage(String text)
Creates an images with the givent text printed inside
-
-
-
Method Detail
-
saveImage
public static void saveImage(String content, File file) throws IOException
Saves an image into a given file in an image format- Parameters:
content
- the content of the image Base64 encodedfile
- the output file- Throws:
IOException
- in case of I/O error
-
cropImageToFile
public static void cropImageToFile(String content, ImageZone zone, File file) throws IOException
Crops an area and stores it in a given .jpg file- Parameters:
content
- the content of the source image Base64 encodedzone
- the zone definitionfile
- the output file- Throws:
IOException
- an I/O error
-
cropImage
public static BufferedImage cropImage(BufferedImage originalImage, ImageZone zone)
Crops an area from given image- Parameters:
originalImage
- the original imagezone
- the zone definition- Returns:
- the cropped image
-
cropCenterSquare
public static BufferedImage cropCenterSquare(BufferedImage originalImage, int squareSize)
Crops a square at the center of the given image- Parameters:
originalImage
- the original imagesquareSize
- size of the square- Returns:
- the cropped square
-
cropVisibleContent
public static int[] cropVisibleContent(File src, File dst) throws IOException
Crops an image leaving the smallest square containing something visible- Parameters:
src
- the source image filedst
- the cropped image file (png format)- Returns:
- width and height of the cropped image
- Throws:
IOException
- In case of elaboration error
-
pasteImage
public static void pasteImage(BufferedImage container, BufferedImage imageIn, float opaque, int x, int y)
Prints the contents of imageIn on container the given opaque value- Parameters:
container
- the bigger imageimageIn
- the image to print inopaque
- and indication of how opaque must be the printx
- left coordinatey
- top coordinate
-
encodeImage
public static String encodeImage(File image) throws FileNotFoundException, IOException
Encodes in Base64 the given image file- Parameters:
image
- the image to encode- Returns:
- the encoded image
- Throws:
IOException
- error in the elaboration of the imageFileNotFoundException
- error accessing the file
-
printFirstPage
public static void printFirstPage(File originalFile, String originalFileName, File out) throws IOException
Prints the first page of the given file into the output as .jpg image- Parameters:
originalFile
- the original fileoriginalFileName
- the original filenameout
- the output .jpg file- Throws:
IOException
- a generic I/O error
-
isBlack
public static boolean isBlack(BufferedImage image, int x, int y)
Whether the pixel is black.- Parameters:
image
- source imagex
- x coordinatey
- y coordinate- Returns:
- true only if the image is black
-
isBlack
public static boolean isBlack(BufferedImage image, int x, int y, int luminanceCutOff)
Whether the pixel is black.- Parameters:
image
- source imagex
- x coordinatey
- y coordinateluminanceCutOff
- cut off luminance- Returns:
- true only if the image is black
-
rotate
public static BufferedImage rotate(BufferedImage image, double angle, int cx, int cy)
Rotates image.- Parameters:
image
- source imageangle
- by degreescx
- x-coordinate of pivot pointcy
- y-coordinate of pivot point- Returns:
- rotated image
-
getScaledInstance
public static BufferedImage getScaledInstance(BufferedImage image, int targetWidth, int targetHeight)
Convenience method that returns a scaled instance of the providedBufferedImage
.- Parameters:
image
- the original image to be scaledtargetWidth
- the desired width of the scaled instance, in pixelstargetHeight
- the desired height of the scaled instance, in pixels- Returns:
- a scaled version of the original
BufferedImage
-
getScaledInstance
public static IIOImage getScaledInstance(IIOImage iioSource, float scale)
Convenience method that returns a scaled instance of the providedIIOImage
.- Parameters:
iioSource
- the original image to be scaledscale
- the desired scale- Returns:
- a scaled version of the original
IIOImage
-
getSubImage
public static BufferedImage getSubImage(BufferedImage image, int x, int y, int width, int height)
A replacement for the standardBufferedImage.getSubimage
method.- Parameters:
image
- the image to take the sub area fromx
- the X coordinate of the upper-left corner of the specified rectangular regiony
- the Y coordinate of the upper-left corner of the specified rectangular regionwidth
- the width of the specified rectangular regionheight
- the height of the specified rectangular region- Returns:
- a BufferedImage that is the subimage of
image
.
-
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
-
convertImage2Binary
@Deprecated public static BufferedImage convertImage2Binary(BufferedImage image)
Deprecated.As of release 1.1, renamed toconvertImageToBinary(BufferedImage image)
A simple method to convert an image to binary or B/W image.- Parameters:
image
- input image- Returns:
- a monochrome image
-
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 imageangle
- the degree of rotation- Returns:
- a rotated image
-
getClipboardImage
public static Image getClipboardImage()
Gets an image from Clipboard.- Returns:
- image the image to process
-
cloneImage
public static BufferedImage cloneImage(BufferedImage bi)
Clones an image.- Parameters:
bi
- the image to clone- Returns:
- the cloned image
-
textToImage
public static BufferedImage textToImage(String text)
Creates an images with the givent text printed inside- Parameters:
text
- the text to print in the image- Returns:
- The generated image
-
-