public class GraphicsUtils extends java.lang.Object
| Constructor and Description |
|---|
GraphicsUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.awt.Color |
addToColorChannels(java.awt.Color color,
int addend)
Adds a constant value to all color channels of the specified color.
|
static java.awt.Color |
blend(java.awt.Color... colors)
Blends different colors.
|
static int |
brightnessDifference(java.awt.Color c1,
java.awt.Color c2)
Returns the sum of the absolute differences the three channels of the two colors.
|
static java.lang.String |
colorToHexString(java.awt.Color color) |
static void |
drawStringInRectangle(java.awt.Graphics2D g,
java.awt.geom.Rectangle2D rectangle,
java.lang.String text)
Draws the specified string into the center of the specified rectangle.
|
static java.awt.Color |
getContrastColor(java.awt.Color color,
java.awt.Color background,
int minDifference)
Returns the specified color if it differs enough from the given background color.
|
static java.awt.Color |
invertColor(java.awt.Color color) |
static java.awt.Color |
moveColorToCenter(java.awt.Color color,
float factor)
The result of the method depends on the specified color.
|
static java.awt.Color |
multiplyColorChannels(java.awt.Color color,
float factor)
Multiplies all color channels of the specified color with the specified value.
|
static java.awt.Color |
rgbToGrayColor(java.awt.Color color)
Returns the according gray scale color to the specified color.
|
static int |
rgbToGrayValue(java.awt.Color color)
Returns the according gray scale value to the specified color.
|
public GraphicsUtils()
public static int rgbToGrayValue(java.awt.Color color)
color - the color to be convertedrgbToGrayColor(Color)public static java.awt.Color rgbToGrayColor(java.awt.Color color)
color - the color to be convertedrgbToGrayValue(Color)public static java.awt.Color multiplyColorChannels(java.awt.Color color, float factor)
This method can be used as an alternative to Color.brighter() and Color.darker()n which
always multiply with a constant factor.
color - the color to changedfactor - the factor to be multiplied with the channel valuesmoveColorToCenter(Color, float)public static java.awt.Color addToColorChannels(java.awt.Color color, int addend)
Channel values will never become higher than 255 or lower than 0.
color - the color to changedaddend - the value to be add to all color channelspublic static java.awt.Color moveColorToCenter(java.awt.Color color, float factor)
color is greater than
127 all color channels are multiplied by factor. If the gray value is lower all color channels are
divided by factor. The alpha channel is not changed.
Channel values will never become higher than 255 or lower than 0.
color - the color to be modifiedfactor - the scale factor for the color channelsmultiplyColorChannels(Color, float)public static int brightnessDifference(java.awt.Color c1, java.awt.Color c2)
c1 - c2 - public static java.awt.Color invertColor(java.awt.Color color)
public static java.awt.Color getContrastColor(java.awt.Color color, java.awt.Color background, int minDifference)
color - the designated foreground colorbackground - the background colorminDifference - the minimal difference the two colors must have so that the
designated color is returnedpublic static java.awt.Color blend(java.awt.Color... colors)
colors - an array of colors (should contain at least two elements)public static java.lang.String colorToHexString(java.awt.Color color)
public static void drawStringInRectangle(java.awt.Graphics2D g, java.awt.geom.Rectangle2D rectangle, java.lang.String text)
g - the graphics context to paint torectangle - the rectangle to fit the text intotext - the text to be drawnFontCalculator.fontToFitRectangle(Rectangle2D, double, String, String, int, int)