Class ColorUtils

java.lang.Object
net.thevpc.common.swing.color.ColorUtils

public class ColorUtils extends Object
Author:
thevpc
  • Field Details

  • Constructor Details

    • ColorUtils

      public ColorUtils()
  • Method Details

    • formatPaint

      public static String formatPaint(Paint s)
    • parseColor

      public static Color parseColor(String s)
    • formatColor

      public static String formatColor(Color s)
    • parsePaint

      public static Paint parsePaint(String s)
    • getCheckerBoard

      public static TexturePaint getCheckerBoard(int checkerSize, Color color1, Color color2)
    • changeAlpha

      public static Color changeAlpha(Color c, int alpha)
      / g.drawLine(0, h/2, w, h/2); / g.drawLine(0, h, w, h); / break; / } / }
    • blendColors

      public static Color blendColors(Paint c1, Color c2, double amt)
    • blendColors

      public static Color blendColors(Color c1, Paint c2, double amt)
    • getForegroundColorFromBackgroundColor

      public static final Color getForegroundColorFromBackgroundColor(Paint color)
      Returns a foreground color (for text) given a background color by examining the brightness of the background color.
      Parameters:
      color - the foreground color
      Returns:
      Color
    • blendColors

      public static Color blendColors(Color c1, Color c2, double amt)
    • addColors

      public static Color addColors(Color c1, Color c2, double amt)
    • convertColor

      public static final float[] convertColor(Color color)
      Returns an array of color components for the given Color object.
      Parameters:
      color - the color object
      Returns:
      float[]
    • convertColor

      public static final Color convertColor(float[] color)
      Returns a new Color object given the color components in the given array.
      Parameters:
      color - the color components in RGB or RGBA
      Returns:
      Color
    • convertColor

      public static final void convertColor(Color color, float[] destination)
      Places the RGBA values from the given Color object into the destination array.
      Parameters:
      color - the color to convert
      destination - the array to hold the RGBA values; length 4
    • getBrightness

      public static final int getBrightness(Paint color)
    • getBrightness

      public static final int getBrightness(Color color)
      Uses the method described at http://alienryderflex.com/hsp.html to get the perceived brightness of a color.
      Parameters:
      color - the color
      Returns:
      int brightness on the scale of 0 to 255
    • getForegroundColorFromBackgroundColor

      public static final Color getForegroundColorFromBackgroundColor(Color color)
      Returns a foreground color (for text) given a background color by examining the brightness of the background color.
      Parameters:
      color - the foreground color
      Returns:
      Color
    • getInvertColor

      public static final Color getInvertColor(Color color)
      Returns a foreground color (for text) given a background color by examining the brightness of the background color.
      Parameters:
      color - the foreground color
      Returns:
      Color
    • getRandomColor

      public static final Color getRandomColor(float offset, float alpha)
      Returns a random color given the offset and alpha values.
      Parameters:
      offset - the offset between 0.0 and 1.0
      alpha - the alpha value between 0.0 and 1.0
      Returns:
      Color
    • getColor

      public static final Color getColor(Color color, float factor)
      Returns a new color that is darker or lighter than the given color by the given factor.
      Parameters:
      color - the color to modify
      factor - 0.0 ≤ factor ≤ 1.0 darkens; 1.0 < factor brightens
      Returns:
      Color
      Since:
      1.0.1
    • paintToColor

      public static Color paintToColor(Paint color)