Class ColorHelper

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

public final class ColorHelper
extends java.lang.Object
  • Method Summary

    Modifier and TypeMethodDescription
    static java.awt.Colordecode​(java.lang.String colorHexString)
    Decodes the specified color string to an actual Color instance.
    static java.awt.Colordecode​(java.lang.String colorHexString, boolean solid) 
    static java.lang.Stringencode​(java.awt.Color color)
    Encodes the specified color to a hexadecimal string representation.
    static intensureColorValueRange​(float value)
    Ensures that the specified value lies within the accepted range for Color values (0-255).
    static intensureColorValueRange​(int value)
    Ensures that the specified value lies within the accepted range for Color values (0-255).
    static java.awt.Colorpremultiply​(java.awt.Color color)
    Premultiplies the alpha on the given color.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • encode

      public static java.lang.String encode​(java.awt.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(String), Color, Color.getRGB(), Integer.toHexString(int)
    • decode

      public static java.awt.Color decode​(java.lang.String colorHexString)
      Decodes the specified color string to an actual Color instance. The accepted format is:
      • #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:
      encode(Color), Color, Color.decode(String), Integer.decode(String)
    • decode

      public static java.awt.Color decode​(java.lang.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 java.awt.Color premultiply​(java.awt.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.