Convert Color Codes – C# Examples and Online Converter

Parse Colors

Aspose.SVG for .NET API offers a high-speed C# library that you can use for different SVG parsing tasks. One of the API features is easy access to work with several color spaces. The Color class allows you to parse colors (such as RGB, HEX, HSL, HWB, CMYK, NCOL, LCH, OKLCH, LAB, OKLAB) from a string representation and convert them to the desired color space. Colors codes and formats play a crucial role in various fields such as web design, graphic design, photography, art and more. Different tasks may require different color formats, hence the need for color conversion functionality.

Online Color Converter

Colors can be specified as common Color Names or defined in popular HEX codes or RGB, HSL, HSV, LAB, HWB, CMYK, LCH, XYZ, and NCOL values. And for different tasks, different color formats are preferred. You can convert color codes to various most popular formats in any way – online or programmatically! You simply need to enter the color value for conversion! Click inside the color area to select a color, or enter a color code in the Input text box. You will immediately see other color codes for chosen color in the Output section.

How to Convert Color Codes

If you want to use the conversion functions in your product or programmatically convert color codes, see the C# code example below. Here we convert HEX to RGB. Color conversion can be done with a few lines of code:

  1. The FromString("#ff31ca") method of the Color class is used to parse the HEX color code from its string representation and returns a color instance.
  2. The ToRgbString() method is used to convert the color from HEX to the RGB color space. The format is: rgb(0, 0, 0).
  3. The result of the RGB color value is printed to the console using Console.WriteLine(rgbColor).

The following code snippet illustrates how to convert HEX to RGB:

 1using Aspose.Svg;
 2using Aspose.Svg.Drawing;
 3...
 4
 5    // Parse HEX color from a string
 6    var color = Color.FromString("#ff31ca");
 7
 8    // Convert HEX to RGB 
 9    string rgbColor = color.ToRgbString();
10
11    // Print result to console
12    Console.WriteLine(rgbColor);
13    //result should be: rgb(255, 49, 202)

The article SVG Color looks at how SVG text and shapes can be colorized. You’ll find an overview of how color is defined, including the various ways you can control the transparency of SVG content.

The How to Change SVG Color article shows how to work with SVG color using Aspose.SVG for .NET library and consider how to change SVG color of elements or change background color in SVG files.

Color Codes

The RGB (Red, Green, Blue) color space consists of all possible colors that can be obtained by mixing red, green, and blue. This color model is popular in photography, TV and computer graphics. RGB values are specified as an integer between 0 and 255. So, for example, rgb(255,0,0) is displayed as red. The red parameter is set to its highest value (255), and the rest are set to 0.
Aspose.SVG C# library supports RGB percentages (from 0% to 100%). For example, rgb(100%,0,0) is displayed as red.

HEX (#RRGGBB) codes are the most used color codes. This is because they are simple and easy to understand. HEX codes are nothing more than a hexadecimal representation of RGB. The six-digit color number is structured into three groups of two digits which specify the amount of Red, Green, and Blue in the additive color. Each two-digit hex pair can have a value from 00 to FF. This gives over 16 million possible colors. If each of the three groups contains characters, such as #RRGGBB, then they can be written as #RGB. Hexadecimal color values are supported in all browsers.

HSL (Hue, Saturation, Lightness) is a representation of the RGB color model in cylindrical coordinates. Hue is any color on the color wheel; it’s a degree on the color wheel from 0 to 360. So, 0 is red, 120 is green, 240 is blue. Saturation is the intensity or purity of a color. It determines how vivid the color will be. For example, zero percent is gray, and 100 percent is a fully saturated color. Lightness is the amount of brightness or light in color. Lightness determines how much black or white tint the color has. For example, 50 percent has no tint, zero percent is entirely black, and 100 percent is fully white.

HSV stands for Hue, Saturation and Value (brightness value). HSV is similar to HSL, but they are two different color models. They are both based on cylindrical geometries, but HSV is based on the “hexcone” model, while HSL is based on the “bi-hexcone” model. Selecting an HSV color begins with picking one of the available hues and then adjusting the shade and brightness values. Hue sets the position of the color on the color wheel (from 0 to 360). Saturation is a saturation percentage value (from 0% to 100%). Brightness is a brightness percentage (from 0% to 100%).

Like geographic coordinates – longitude, latitude and height – the color values LAB give us a way to detect colors. LAB uses three axes: L – Lightness, a* – from Red to Green Value, and b* – from Blue to Yellow Value. The Lightness is expressed as a percentage and can exceed 100%. Values for the a and b axes can range from positive to negative. It is commonly clamped to the range of −128 to 127 for use with integer code values. The LAB color space and LAB color codes are recommended to use if you want the color on-screen to look the same as when printed on paper.

LCH stands for Lightness, Chroma, and Hue. As with LAB, the Lightness can be a percentage that exceeds 100%. The color components in the LCH color model loosely correspond to HSL’s. Similar to HSL, hue can be a range between 0 and 360. However, the LCH Hue angles don’t fully correspond to the same HSL’s hue values. Chroma represents the amount of color, and we can think of it as similar to saturation in HSL. But chroma can exceed 100 – in fact, it’s theoretically unbounded. LCH color space as LAB is perceptual uniform, meaning the exact numerical change of coordinates in the color space gives the same perceptual difference between colors.

HWB stands for hue, whiteness and blackness. The HWB is very similar to the color models HSV (Hue, Saturation, Value) and HSL (Hue, Saturation, Lightness), except that neither HSV nor HSL provide white saturation. Like HSL and HSV, the hue can be anywhere within a range of 0 to 360. The other two arguments control how much white or black is mixed into that hue, up to 100% (which would result in a totally white or black color). HWB is especially useful for creating monochrome color palettes. HWB is not supported in HTML yet, but it is suggested as a new standard in CSS4.

The XYZ color model (CIE 1931 XYZ) is a purely mathematical space based on the results of the CIE RGB version of the human eye. Unlike RGB, CMYK, and other models, in XYZ the primary components are hypothetical, meaning you can’t map X, Y, and Z to any set of colors to mix. These colors do not correspond to any real light wavelengths. XYZ is an additive scheme of color spaces since it defines the amounts of three stimuli provided to the eye (the three primaries). XYZ is widely used in scientific works and technical fields. Color descriptions in other color spaces are often related to their representation in this space.

RGBA (Red, Green, Blue, and Alpha) color values are an extension of RGB color values with an alpha channel that determines the opacity of the color. The alpha parameter is a number between 0.0 and 1.0 that specifies transparency. For example, rgba(255, 0, 0) is displayed as pure red, rgba(255, 0, 0, 0.5) is displayed as red with 50% opacity. For an RGBA value, unlike RGB values, there is no hexadecimal notation.

Similar to RGB/RGBA, HSL has an HSLA mode with support for an alpha channel to specify the color opacity. The HSLA (Hue, Saturation, Lightness, Alpha) color value is specified with hue, saturation, lightness, and alpha, where the alpha parameter specifies the opacity. The alpha parameter is a number between 0.0, meaning “fully transparent”, and 1.0, meaning “fully opaque”. For example, hsla(0, 100%, 50%, 1) is displayed as pure red, hsla(0, 100%, 50%, 0.5) is displayed as red with 50% opacity.

CMYK colors are a combination of Cyan, Magenta, Yellow, and blacK. This model is known as subtractive, as inks subtract the colors from white. CMYK is one of the most popular color models. The CMYK color model is used in printing inks for paper. This model includes many colors, but the number of colors is limited compared to RGB. CMYK is widely used while creating designs for printing to ensure that the desired colors are accurate and never for style sheets or HTML. CMYK is not supported in HTML, but it is suggested as a new standard in CSS4.

Color Converter is a free online application for transforming colors between color formats. Just enter color code and get the result at once! You don’t need any additional software. Try our forceful Color Converter just now!

Text “Banner Color Converter”

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.