Package jexer.bits
Class ImageUtils
- java.lang.Object
-
- jexer.bits.ImageUtils
-
public class ImageUtils extends java.lang.Object
ImageUtils contains methods to: - Check if an image is fully transparent. - Scale an image and preserve aspect ratio. - 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 class
ImageUtils.Scale
Selections for fitting the image to the text cells.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static Animation
getAnimation(java.io.File file)
Open an image as an Animation.static Animation
getAnimation(java.io.InputStream inputStream)
Open an image as an Animation.static Animation
getAnimation(java.lang.String filename)
Open an image as an Animation.static Animation
getAnimation(java.net.URL url)
Open an image as an Animation.static boolean
isFullyOpaque(java.awt.image.BufferedImage image)
Check if any pixels in an image have not-100% alpha value.static boolean
isFullyTransparent(java.awt.image.BufferedImage image)
Check if any pixels in an image have not-0% alpha value.static int
rgbDistance(int first, int second)
Report the absolute distance in RGB space between two RGB colors.static int
rgbMove(int start, int end, double fraction)
Move from one point in RGB space to another, by a certain fraction.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.
-
-
-
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
-
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
-
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
-
-