Class ColorHelper

java.lang.Object
de.gurkenlabs.litiengine.util.ColorHelper

public final class ColorHelper extends Object
  • Method Details

    • encode

      public static String encode(Color color)
      Encodes the specified color to a hexadecimal string representation. The output format is:
      • #RRGGBB - For colors without alpha
      • #AARRGGBB - For colors with alpha

      Examples:
      Color.RED = "#ff0000"
      new Color(255, 0, 0, 200) = "#c8ff0000"

      Parameters:
      color - The color that is encoded.
      Returns:
      An hexadecimal string representation of the specified color.
      See Also:
    • decode

      public static Color decode(String colorHexString)
      Decodes the specified color string to an actual Color instance. The accepted format is:

      Note: This returns null if the format of the provided color string is invalid.

      • #RRGGBB - For colors without alpha
      • #AARRGGBB - For colors with alpha

      Examples:
      "#ff0000" = Color.RED
      "#c8ff0000" = new Color(255, 0, 0, 200)

      Parameters:
      colorHexString - The hexadecimal encodes color string representation.
      Returns:
      The decoded color.
      See Also:
    • decode

      public static Color decode(String colorHexString, boolean solid)
    • ensureColorValueRange

      public static int ensureColorValueRange(float value)
      Ensures that the specified value lies within the accepted range for Color values (0-255). Smaller values will be forced to be 0 and larger values will result in 255.
      Parameters:
      value - The value to check for.
      Returns:
      An integer value that fits the color value restrictions.
    • ensureColorValueRange

      public static int ensureColorValueRange(int value)
      Ensures that the specified value lies within the accepted range for Color values (0-255). Smaller values will be forced to be 0 and larger values will result in 255.
      Parameters:
      value - The value to check for.
      Returns:
      An integer value that fits the color value restrictions.
    • premultiply

      public static Color premultiply(Color color)
      Premultiplies the alpha on the given color.
      Parameters:
      color - The color to premultiply
      Returns:
      The color given, with alpha replaced with a black background.
    • interpolate

      public static Color interpolate(Color color1, Color color2, double factor)
    • getTransparentVariant

      public static Color getTransparentVariant(Color color, int newAlpha)