Module ij
Package ij.plugin

Class Colors

    • Field Detail

      • colors

        public static final String[] colors
    • Constructor Detail

      • Colors

        public Colors()
    • Method Detail

      • run

        public void run​(String arg)
        Description copied from interface: PlugIn
        This method is called when the plugin is loaded. 'arg', which may be blank, is the argument specified for this plugin in IJ_Props.txt.
        Specified by:
        run in interface PlugIn
      • getColorName

        public static String getColorName​(Color c,
                                          String defaultName)
        For named colors, returns the name, or 'defaultName' if not a named color. If 'defaultName' is non-null and starts with an uppercase character, the returned name is capitalized (first character uppercase). Use colorToString or colorToString2 to get a String representation (hexadecimal) also for unnamed colors.
      • getColor

        public static Color getColor​(String name,
                                     Color defaultColor)
        For named colors, converts the name String to the corresponding color. Returns 'defaultColor' if the color has no name. Use 'decode' to also decode hex color names like "#ffff00"
      • decode

        public static Color decode​(String hexColor)
        Converts a String with the color name or the hexadecimal representation of a color with 6 or 8 hex digits to a Color. With 8 hex digits, the first two digits are the alpha. With 6 hex digits, the color is opaque (alpha = hex ff). A hex String may be preceded by '#' such as "#80ff00". When the string does not include a valid color name or hex code, returns Color.GRAY.
      • decode

        public static Color decode​(String hexColor,
                                   Color defaultColor)
        Converts a String with the color name or the hexadecimal representation of a color with 6 or 8 hex digits to a Color. With 8 hex digits, the first two digits are the alpha. With 6 hex digits, the color is opaque (alpha = hex ff). A hex String may be preceded by "#" such as "#80ff00" or "0x". When the string does not include a valid color name or hex code, returns 'defaultColor'.
      • getRed

        public static int getRed​(String hexColor)
      • getGreen

        public static int getGreen​(String hexColor)
      • getBlue

        public static int getBlue​(String hexColor)
      • hexToColor

        public static String hexToColor​(String hex)
        Converts a hex color (e.g., "ffff00") into "red", "green", "yellow", etc. Returns null if the hex color does not have a name. Unused in ImageJ, for compatibility only.
      • hexToColor2

        public static String hexToColor2​(String hex)
        Converts a hex color (e.g., "ffff00" or "#ffff00") into a color name "Red", "Green", "Yellow", etc. Returns null if the hex color does not have a name. Unused in ImageJ, for compatibility only.
      • colorToString

        public static String colorToString​(Color color)
        Converts a Color into a lowercase string ("red", "green", "#aa55ff", etc.). If color is null, returns the String "none".
      • colorToString2

        public static String colorToString2​(Color color)
        Converts a Color into a string ("Red", "Green", #aa55ff, etc.). If color is null, returns the String "None".
      • toColor

        public static Color toColor​(int red,
                                    int green,
                                    int blue)
        Returns an opaque color with the specified red, green, and blue values. Values is outside the 0-255 range are replaced by the nearest valid number (0 or 255)
      • getColors

        public static String[] getColors​(String... moreColors)
        Returns an array of the color Strings in the argument(s) and the 13 predefined color names "Red", "Green", ... "Pink". The Strings arguments must be either "None" or hex codes starting with "#". Any null arguments are ignored.
      • wavelengthToColor

        public static Color wavelengthToColor​(double wl)
        Converts a wavelength (380-750 nm) to color. Based on the wavelength_to_rgb.R program at https://gist.github.com/friendly/67a7df339aa999e2bcfcfec88311abfc, which in turn is based on a FORTRAN program at http://www.physics.sfasu.edu/astro/color.html.