https://github.com/abjerner/skybrud.colors
A library for working with various color models and color conversion in .NET.
https://github.com/abjerner/skybrud.colors
cmy cmyk color color-model color-models colors csharp dotnet hsl limbo package rgb skybrud
Last synced: about 2 months ago
JSON representation
A library for working with various color models and color conversion in .NET.
- Host: GitHub
- URL: https://github.com/abjerner/skybrud.colors
- Owner: abjerner
- License: mit
- Created: 2016-10-14T14:48:10.000Z (almost 9 years ago)
- Default Branch: v1/main
- Last Pushed: 2024-03-06T18:17:04.000Z (over 1 year ago)
- Last Synced: 2025-07-22T07:10:42.759Z (3 months ago)
- Topics: cmy, cmyk, color, color-model, color-models, colors, csharp, dotnet, hsl, limbo, package, rgb, skybrud
- Language: C#
- Homepage: https://packages.limbo.works/skybrud.colors/
- Size: 1.18 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Skybrud.Colors
[](https://github.com/abjerner/Skybrud.Colors/blob/v1/main/LICENSE.md)
[](https://www.nuget.org/packages/Skybrud.Colors)
[](https://www.nuget.org/packages/Skybrud.Colors)
[](https://packages.limbo.works/skybrud.colors/)**Skybrud.Colors** is a small library for working with various color models, currently supporting RGB, CMY, CMYK and HSL. The library features converters for converting back and forth between the supported color models.
## Installation
Install the package via [**NuGet**](https://www.nuget.org/packages/Skybrud.Colors). To install the package, you can use either .NET CLI:
```
dotnet add package Skybrud.Colors
```or the NuGet Package Manager:
```
Install-Package Skybrud.Colors
```
## Usage
Initialize a new `RgbColor` instance and convert to various string formats and other color models:
```cshtml
@using Skybrud.Colors
@{RgbColor navy = new RgbColor(0, 0, 128);
// Convert to HEX -> #000080
string hex = navy.ToHex();
@hex// Convert to CSS -> rgb(0, 0, 128)
string css = navy.ToCss();
@css// Convert to HSL -> HSL: 240, 100, 25
HslColor hsl = navy.ToHsl();
@hsl// Convert to CMY -> CMY: 100, 100, 50
CmyColor cmy = navy.ToCmy();
@cmy// Convert to CMYK -> CMYK: 100, 100, 0, 50
CmykColor cmyk = navy.ToCmyk();
@cmyk}
```Get the WCAG contrast ratio between two instances of `RgbColor`:
```cshtml
@using Skybrud.Colors
@using Skybrud.Colors.Html
@using Skybrud.Colors.Wcag
@{// Get colors from the constants in the "HtmlColors" class
RgbColor red = HtmlColors.Red;
RgbColor blue = HtmlColors.Blue;
// Calculate the WCAG contrast ratio
double ratio = WcagHelpers.GetContrastRatio(red, blue);
WCAG ratio: @ratio}
```Get a list of hex colors representing gradient steps between two hex colors:
```cshtml
@using Skybrud.Colors@{
//Get gradient colors Blue to Red
var colors = Skybrud.Colors.ColorUtils.GetGradientColorsHexCodes("#0000ff", "#ff0000", 10);
Start: #0000ff | End: #ff0000
@foreach (var color in colors)
{
@color
}
}
```
[NuGetPackage]: https://www.nuget.org/packages/Skybrud.Colors
[GitHubRelease]: https://github.com/abjerner/Skybrud.Colors/releases/latest
[Changelog]: https://github.com/abjerner/Skybrud.Colors/releases
[Issues]: https://github.com/abjerner/Skybrud.Colors/issues