Aller au contenu
uencoder

Comment en Convertir Color Formats

Convertir colors between HEX, RGB, HSL, HSV, and named color formats.

问题

You avoir un color en one formater (e.g., HEX) et besoin it en another (e.g., RGB ou HSL) pour un différent outil ou context.

Prérequis

  • Understanding of color models
  • Familiarity with CSS color formats

Étapes

  1. 1. Parse the source color

    Identify the input format: HEX (#FF5733), RGB (rgb(255,87,51)), HSL (hsl(11,100%,60%)), or a named color (red). Parse it into an intermediate representation, typically RGB values, for conversion to other formats.

    entrée
    #FF5733
    输出
    RGB: (255, 87, 51)
  2. 2. Convert to the target format

    Convert from RGB to the target: HEX concatenates the hex values, HSL converts via the RGB-to-HSL algorithm, HSV uses a similar but distinct conversion. Each conversion is lossless within the color gamut. Alpha (transparency) is preserved separately.

    entrée
    RGB (255,87,51) → HSL
    输出
    hsl(11, 100%, 60%)
  3. 3. Verify and output

    Convert back to the original format and compare to verify lossless conversion. Output the result in the target format with correct syntax. For CSS, use the modern syntax: hsl(11 100% 60%) or rgb(255 87 51).

    entrée
    hsl(11, 100%, 60%) → back to HEX
    输出
    #FF5733 ✓

Résultat attendu

Le color converted en le target formater, avec le même visual appearance.

Erreurs courantes

HSL and HSV confused
HSL (Lightness) and HSV (Value) are different models. Lightness goes from black to white through the pure color; Value goes from black to the pure color. Use the correct target.
Alpha channel lost
Preserve the alpha (transparency) channel through conversions. Use rgba(), hsla(), or 8-digit HEX (#FF5733FF) for colors with transparency.

Dépannage指引

  • If the color looks different after conversion, check for gamut issues or rounding errors in intermediate values.
  • Some conversions (like RGB to HSL) involve division; handle the zero-saturation case (grayscale) separately.

Limites de sécurité

  • Color conversion is a pure calculation with no security implications.

Outils associés

参考链接