Convert a color to its hex representation.

@param color the color to convert.
@return the hex.
198538
public static String asHexWithAlpha( Color color ) {
        int r = color.getRed();
        int g = color.getGreen();
        int b = color.getBlue();
        int a = color.getAlpha();

        String hex = String.format("#%02x%02x%02x%02x", r, g, b, a);
        return hex;
    }
826017
@ColorInt
    public static int opaqueColor(@ColorInt int color) {
        int alpha = Color.alpha(color);
        if (alpha == 0) return color;
        int red = Color.red(color);
        int green = Color.green(color);
        int blue = Color.blue(color);
        return Color.argb(255, red, green, blue);
    }
732800
public void setColor(String color) {
		setRed(ColorUtils.getRed(color));
		setGreen(ColorUtils.getGreen(color));
		setBlue(ColorUtils.getBlue(color));
		String alpha = ColorUtils.getAlpha(color);
		if (alpha != null) {
			setAlpha(alpha);
		}
	}
955133
public static Color colorWithoutAlpha( Color color ) {
        return new Color(color.getRed(), color.getGreen(), color.getBlue());
    }
200610
public static int getOpacityFromColor(int color) {
    int colorAlpha = color >>> 24;
    if (colorAlpha == 255) {
      return PixelFormat.OPAQUE;
    } else if (colorAlpha == 0) {
      return PixelFormat.TRANSPARENT;
    } else {
      return PixelFormat.TRANSLUCENT;
    }
  }
87472
def hex_to_rgb(self, h):
        """"""
        rgb = (self.hex_to_red(h), self.hex_to_green(h), self.hex_to_blue(h))
        return rgb
1141771
public static final Color hex2RGB(final String hex)
    {
        String r, g, b;

        final int len = hex.length();

        if (len == 7)
        {
            r = hex.substring(1, 3);

            g = hex.substring(3, 5);

            b = hex.substring(5, 7);
        }
        else if (len == 4)
        {
            r = hex.substring(1, 2);

            g = hex.substring(2, 3);

            b = hex.substring(3, 4);

            r = r + r;

            g = g + g;

            b = b + b;
        }
        else
        {
            return null;// error - invalid length
        }
        try
        {
            return new Color(Integer.valueOf(r, 16), Integer.valueOf(g, 16), Integer.valueOf(b, 16));
        }
        catch (final NumberFormatException ignored)
        {
            return null;
        }
    }
901637
public static int getDeclinedColorFromColor(int color) {
        int bg = 0xffffffff;
        int a = DECLINED_EVENT_ALPHA;
        int r = (((color & 0x00ff0000) * a) + ((bg & 0x00ff0000) * (0xff - a))) & 0xff000000;
        int g = (((color & 0x0000ff00) * a) + ((bg & 0x0000ff00) * (0xff - a))) & 0x00ff0000;
        int b = (((color & 0x000000ff) * a) + ((bg & 0x000000ff) * (0xff - a))) & 0x0000ff00;
        return (0xff000000) | ((r | g | b) >> 8);
    }
1366492
public int getColorNumber(RtfColor color) {
        int colorIndex = -1;
        for(int i = 0; i < colorList.size(); i++) {
            if(colorList.get(i).equals(color)) {
                colorIndex = i;
            }
        }
        if(colorIndex == -1) {
            colorIndex = colorList.size();
            colorList.add(color);
        }
        return colorIndex;
    }
1119781
public static String shorthandHex(String color) {
		validateHex(color);
		if (color.length() > 5) {
			StringBuilder shorthandColor = new StringBuilder();
			int startIndex = 0;
			if (color.startsWith("#")) {
				shorthandColor.append("#");
				startIndex++;
			}
			for (; startIndex < color.length(); startIndex += 2) {
				String shorthand = shorthandHexSingle(color.substring(
						startIndex, startIndex + 2));
				if (shorthand.length() > 1) {
					shorthandColor = null;
					break;
				}
				shorthandColor.append(shorthand);
			}
			if (shorthandColor != null) {
				color = shorthandColor.toString();
			}
		}

		return color;
	}
1229350
public function getArgbHexString(Color $color)
    {
        $alpha = dechex(255 * $color->alpha);
        return '#' . $alpha . $color->hex;
    }
884610
public static int getDisplayColorFromColor(int color) {
        if (!isJellybeanOrLater()) {
            return color;
        }

        float[] hsv = new float[3];
        Color.colorToHSV(color, hsv);
        hsv[1] = Math.min(hsv[1] * SATURATION_ADJUST, 1.0f);
        hsv[2] = hsv[2] * INTENSITY_ADJUST;
        return Color.HSVToColor(hsv);
    }
850590
public static Color valueOf(String color) {

    Objects.requireNonNull(color, "color");
    Throwable cause = null;
    try {
      Color hexColor = parseHexString(color);
      if (hexColor != null) {
        return hexColor;
      } else {
        String upperColor = BasicHelper.toUpperCase(color);
        Color namedColor = NAME_TO_COLOR_MAP.get(upperColor);
        if (namedColor != null) {
          return namedColor;
        } else if (upperColor.startsWith(ColorModel.RGB.toString())) {
          Color rgbColor = parseRgb(upperColor);
          if (rgbColor != null) {
            return rgbColor;
          }
        } else {
          return GenericColor.valueOf(color).toColor();
        }
      }
    } catch (NumberFormatException e) {
      cause = e;
    }
    throw new IllegalArgumentException(color, cause);
  }
215058
public static function parse($color) 
    {
        if (gettype($color) == "integer") {
            return $color & 0xffffffff;
        }

        $color = "$color";

        if (preg_match('/^#?[0-9a-fA-F]+$/', $color)) {
            $hexColor = $color; 
            if ($hexColor[0] == '#') {
                $hexColor = substr($hexColor, 1);
            }

            switch (strlen($hexColor)) {
                case 3:
                    $numeric = intval($hexColor, 16);
                    return (
                        (($numeric & 0xf00) << 20) |
                        (($numeric & 0xf00) << 16) |
                        (($numeric & 0x0f0) << 16) |
                        (($numeric & 0x0f0) << 12) |
                        (($numeric & 0x00f) << 12) |
                        (($numeric & 0x00f) << 8) | 
                        0xff);
                case 6:
                    return (intval($hexColor, 16) << 8) | 0xff;
                case 8:
                    // Workaround to cope with PHP limitation of intval
                    $numeric = 
                        (intval(substr($hexColor, 0, 4), 16) << 16) |
                        (intval(substr($hexColor, 4, 4), 16));
                    return $numeric;
            }
        }

        throw new \InvalidArgumentException("Invalid color '$color'.");
    }
892718
def hex_2_rgb(self, color):
        
        if not self.RE_HEX.match(color):
            color = "#FFF"
        if len(color) == 7:
            return (int(color[i : i + 2], 16) / 255 for i in [1, 3, 5])
        return (int(c, 16) / 15 for c in color)
397809
public static int toRGB(String color) {
		validateHexSingle(color);
		if (color.length() == 1) {
			color += color;
		}
		return Integer.parseInt(color, 16);
	}
1350941
private function convertColor($color)
    {
        if (is_array($color)) {
            return $color;
        }

        if (preg_match('/^#?([a-z\d])([a-z\d])([a-z\d])$/i', $color, $matches)) {
            $color = $matches[1].$matches[1];
            $color .= $matches[2].$matches[2];
            $color .= $matches[3].$matches[3];
        }

        preg_match('/#?([a-z\d]{2})([a-z\d]{2})([a-z\d]{2})$/i', $color, $matches);

        return array_map(function ($value) {
            return hexdec($value);
        }, array_slice($matches, 1, 3));
    }