Package jexer.bits
Class ImageUtils
- java.lang.Object
-
- jexer.bits.ImageUtils
-
public class ImageUtils extends java.lang.ObjectImageUtils contains methods to: - Check if an image is fully transparent. - Scale an image and preserve aspect ratio. - Break an image up into cells and optionally convert to Unicode glyphs. - Open an animated image as an Animation. - Compute the distance between two colors in RGB space. - Compute the partial movement between two colors in RGB space.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classImageUtils.DisplayModeSelections for approximating an image as text cells.static classImageUtils.ScaleSelections for fitting an image to the text cells.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancanDrawUnicodeBlockDrawingChar(int ch)Check if a Unicode block-drawing character is drawable by drawUnicodeBlockDrawingChar().static java.awt.image.BufferedImagecreateImage(java.awt.image.BufferedImage image, int width, int height)Create a BufferedImage using the same color model as another image.static voiddrawUnicodeBlockDrawingChar(int ch, java.awt.Color foreColor, java.awt.Color backColor, java.awt.image.BufferedImage image)Draw a Unicode block-drawing character to an image.static AnimationgetAnimation(java.io.File file)Open an image as an Animation.static AnimationgetAnimation(java.io.InputStream inputStream)Open an image as an Animation.static AnimationgetAnimation(java.lang.String filename)Open an image as an Animation.static AnimationgetAnimation(java.net.URL url)Open an image as an Animation.static Cell[][]imageToCells(Backend backend, java.awt.image.BufferedImage image, int textWidth, int textHeight, ImageUtils.DisplayMode displayMode, java.awt.Color backColor, boolean bleedThrough)Convert an image to a 2D array of cells.static booleanisFullyOpaque(java.awt.image.BufferedImage image)Check if any pixels in an image have not-100% alpha value.static booleanisFullyTransparent(java.awt.image.BufferedImage image)Check if any pixels in an image have not-0% alpha value.static intrgbAverage(java.awt.image.BufferedImage image)Compute the average RGB value of an entire image, including pixels that may be partially or fully transparent.static intrgbAverage(java.awt.image.BufferedImage image, boolean onlyOpaque)Compute the average RGB value of an entire image.static intrgbDistance(int first, int second)Report the absolute distance in RGB space between two RGB colors.static intrgbMove(int start, int end, double fraction)Move from one point in RGB space to another, by a certain fraction.static doublergbStdDev(java.awt.image.BufferedImage image, java.awt.image.BufferedImage averageImage)Compute the standard deviation of RGB values of an entire image.static java.awt.image.BufferedImagescaleImage(java.awt.image.BufferedImage image, int width, int height, ImageUtils.Scale scale, java.awt.Color backColor)Scale an image to be scaleFactor size and/or stretch it to fit a target box.
-
-
-
Method Detail
-
isFullyTransparent
public static boolean isFullyTransparent(java.awt.image.BufferedImage image)
Check if any pixels in an image have not-0% alpha value.- Parameters:
image- the image to check- Returns:
- true if every pixel is fully transparent
-
isFullyOpaque
public static boolean isFullyOpaque(java.awt.image.BufferedImage image)
Check if any pixels in an image have not-100% alpha value.- Parameters:
image- the image to check- Returns:
- true if every pixel is fully transparent
-
scaleImage
public static java.awt.image.BufferedImage scaleImage(java.awt.image.BufferedImage image, int width, int height, ImageUtils.Scale scale, java.awt.Color backColor)Scale an image to be scaleFactor size and/or stretch it to fit a target box.- Parameters:
image- the image to scalewidth- the width in pixels for the destination imageheight- the height in pixels for the destination imagescale- the scaling typebackColor- the background color to use for Scale.SCALE- Returns:
- the scaled image
-
imageToCells
public static Cell[][] imageToCells(Backend backend, java.awt.image.BufferedImage image, int textWidth, int textHeight, ImageUtils.DisplayMode displayMode, java.awt.Color backColor, boolean bleedThrough)
Convert an image to a 2D array of cells.- Parameters:
image- the image to convertbackend- the backend that can obtain the correct background color for a text celltextWidth- the width of a cell in pixelstextHeight- the height of a cell in pixelsdisplayMode- option to convert image to Unicode glyphsbackColor- the color to use for the right and bottom padding to the text cell boundarybleedThrough- if true, then image cells that are fully covered by a single color will be replaced by empty text cells of that color, permitting text "behind" that cell to bleed through if translucence is enabled- Returns:
- a two-dimensional array of cells (cells[x][y])
-
getAnimation
public static Animation getAnimation(java.lang.String filename)
Open an image as an Animation.- Parameters:
filename- the name of the file that contains an animation- Returns:
- the animation, or null on error
-
getAnimation
public static Animation getAnimation(java.io.File file)
Open an image as an Animation.- Parameters:
file- the file that contains an animation- Returns:
- the animation, or null on error
-
getAnimation
public static Animation getAnimation(java.net.URL url)
Open an image as an Animation.- Parameters:
url- the URK that contains an animation- Returns:
- the animation, or null on error
-
getAnimation
public static Animation getAnimation(java.io.InputStream inputStream)
Open an image as an Animation.- Parameters:
inputStream- the inputStream that contains an animation- Returns:
- the animation, or null on error
-
rgbDistance
public static int rgbDistance(int first, int second)Report the absolute distance in RGB space between two RGB colors.- Parameters:
first- the first colorsecond- the second color- Returns:
- the distance
-
rgbMove
public static int rgbMove(int start, int end, double fraction)Move from one point in RGB space to another, by a certain fraction.- Parameters:
start- the starting point colorend- the ending point colorfraction- the amount of movement between start and end, between 0.0 (start) and 1.0 (end).- Returns:
- the final color
-
rgbAverage
public static int rgbAverage(java.awt.image.BufferedImage image)
Compute the average RGB value of an entire image, including pixels that may be partially or fully transparent.- Parameters:
image- the image to check- Returns:
- the average color
-
rgbAverage
public static int rgbAverage(java.awt.image.BufferedImage image, boolean onlyOpaque)Compute the average RGB value of an entire image.- Parameters:
image- the image to checkonlyOpaque- if true, only count pixels that are fully opaque- Returns:
- the average color
-
rgbStdDev
public static double rgbStdDev(java.awt.image.BufferedImage image, java.awt.image.BufferedImage averageImage)Compute the standard deviation of RGB values of an entire image.- Parameters:
image- the image to checkaverageImage- the image's "average" pixel values- Returns:
- the average color
- Throws:
java.lang.IllegalArgumentException- if the two images are of different dimensions
-
createImage
public static java.awt.image.BufferedImage createImage(java.awt.image.BufferedImage image, int width, int height)Create a BufferedImage using the same color model as another image.- Parameters:
image- the original imagewidth- the width of the new imageheight- the height of the new image- Returns:
- the new image
-
canDrawUnicodeBlockDrawingChar
public static boolean canDrawUnicodeBlockDrawingChar(int ch)
Check if a Unicode block-drawing character is drawable by drawUnicodeBlockDrawingChar().- Parameters:
ch- the character to draw- Returns:
- true if drawUnicodeBlockDrawingChar() can draw that character
-
drawUnicodeBlockDrawingChar
public static void drawUnicodeBlockDrawingChar(int ch, java.awt.Color foreColor, java.awt.Color backColor, java.awt.image.BufferedImage image)Draw a Unicode block-drawing character to an image.- Parameters:
ch- the character to drawforeColor- the foreground colorbackColor- the background colorimage- the image to draw onto
-
-