public class GraphicsUtils extends Object
Constructor and Description |
---|
GraphicsUtils() |
Modifier and Type | Method and Description |
---|---|
static Color |
addToColorChannels(Color color,
int addend)
Adds a constant value to all color channels of the specified color.
|
static Color |
blend(Color... colors)
Blends different colors.
|
static int |
brightnessDifference(Color c1,
Color c2)
Returns the sum of the absolute differences the three channels of the two colors.
|
static Color |
getContrastColor(Color color,
Color background,
int minDifference)
Returns the specified color if it differs enough from the given background color.
|
static Color |
invertColor(Color color) |
static Color |
moveColorToCenter(Color color,
float factor)
The result of the method depends on the specified color.
|
static Color |
multiplyColorChannels(Color color,
float factor)
Multiplies all color channels of the specified color with the specified value.
|
static Color |
rgbToGrayColor(Color color)
Returns the according gray scale color to the specified color.
|
static int |
rgbToGrayValue(Color color)
Returns the according gray scale value to the specified color.
|
public GraphicsUtils()
public static int rgbToGrayValue(Color color)
color
- the color to be convertedrgbToGrayColor(Color)
public static Color rgbToGrayColor(Color color)
color
- the color to be convertedrgbToGrayValue(Color)
public static Color multiplyColorChannels(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 Color addToColorChannels(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 added to all color channelspublic static Color moveColorToCenter(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(Color c1, Color c2)
c1
- c2
- public static Color invertColor(Color color)
public static Color getContrastColor(Color color, 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 returned