E4rth.ColorBlender 1.0.1

dotnet add package E4rth.ColorBlender --version 1.0.1                
NuGet\Install-Package E4rth.ColorBlender -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="E4rth.ColorBlender" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add E4rth.ColorBlender --version 1.0.1                
#r "nuget: E4rth.ColorBlender, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install E4rth.ColorBlender as a Cake Addin
#addin nuget:?package=E4rth.ColorBlender&version=1.0.1

// Install E4rth.ColorBlender as a Cake Tool
#tool nuget:?package=E4rth.ColorBlender&version=1.0.1                

Color Blender

This is a Color Blending library that implements all the blending modes introduced in the W3C Compositing and Blending spec.

Table of Content

Features

Blend Modes

This library provides an implementation for all blend modes listed in the W3C document, such as:

  • Normal
  • Multiply
  • Screen
  • Overlay
  • Darken
  • Lighten
  • Color Dodge
  • Color Burn
  • Hard Light
  • Soft Light
  • Difference
  • Exclusion
  • Hue
  • Color
  • Luminosity
  • Saturation

Color types

Build-in support for commonly used color types: Unit Rgb, Rgb, Hsl, Hex and Color from Sytem.Drawing assembly.

Unit Rgb

It is a higher precision form of RGB color that uses decimal values. All the inner blending calculations are performed in this form of a color. The Red, Green, Blue and Alpha channels are represented by a fractional value between 0 and 1.

RGB

The Red, Green and Blue channels are represented by a fractional value between 0 and 255. The Alpha channel is represented by a fractional value between 0 and 1.

Color

Default Color struct from System.Drawing assembly

HSL

The Hue channel is represented by a fractional value between 0 and 360. The Saturation and Luminosity channels are represented by a fractional value between 0 and 100. The Alpha channel is represented by a fractional value between 0 and 1.

HEX

The Red, Green, Blue and Alpha channels are represented by a hexadecimal form of a String between "00" and "ff". Class constructor supports any form of a Hex color, such as it's short form #rgb, and full forms with leading or trailing Alpha channel (#aarrggbb and #rrggbbaa) with an optional # sign. The Hex Object also can be represented as a String with all the forms described above.

Example

using ColorBlender;

static void Main(string[] args)
{
    var hex        = new HEX("#bbccdd");
    var anotherHex = new HEX("bbccdd");
    var ahex       = new HEX("#aabbccdd", EHEXFormat.AHEX);
    var hexa       = new HEX("#bbccddaa", EHEXFormat.HEXA);
    var shortHex   = new HEX("#abc");
    var userHex    = new HEX("bb", "cc", "dd", "aa");

    var resultHexAOpt = hex.ToString(EHEXOutputFormat.HEXAOpt, EHashSignFormat.Visible);
    // Result: "#bbccdd"

    var resultOptAHex = hex.ToString(EHEXOutputFormat.OptAHEX, EHashSignFormat.Hidden);
    // Result: "bbccdd"

    var resultHexAConst = hex.ToString(EHEXOutputFormat.HEXAConst, EHashSignFormat.Visible);
    // Result: "#bbccddff"

    var resultConstAHex = hex.ToString(EHEXOutputFormat.ConstAHEX, EHashSignFormat.Hidden);
    // Result: "ffbbccdd"
}

Converter

Built-in converter for all the color types described above, with an optional output rounding.

Usage

using ColorBlender;

private readonly IColorConverterService _colorConverterService = new ColorConverterService();

static void Main(string[] args)
{
   var rgb = new RGB(211, 107, 184, 0.94);

   var resultRgb = _colorConverterService.ToRgb(rgb);
   // Result: new RGB(211, 107, 184, 0.94);

   var resultHex = _colorConverterService.ToHex(rgb);
   // Result: new HEX("d3", "6b", "b8", "ef")

   var resultHsl = _colorConverterService.ToHsl(rgb);
   // Result: new HSL(315, 54, 62, 0.94)

   var resultColor = _colorConverterService.ToColor(rgb);
   // Result: new Color(211, 107, 184, 240) *;

   // Conversion with rounding (Input Color, Rounding, Number of decimal places in the return value)
   var resultUrgb  = _colorConverterService.ToURgb(rgb, true, 5);
   // Result: new URGB(0.82645, 0.41961, 0.72157, 0.94);
}

* This is not a proper way to create a system color. It is used here in this form only to display the result.

Blending

Create an instance of the ColorBlenderService and use it blend your colors. The result of the blending will be returned as an Object of a Uniform Color type, that can be further represented as any color type you want. See the example bellow.

Usage

using ColorBlender;

private readonly IColorBlenderService _colorBlenderService = new ColorBlenderService();

static void Main(string[] args)
{
    var background = new RGB(105, 151, 206, 0.8);
    var foreground = new RGB(247, 92, 177, 0.7);

    RGB resultRgb = _colorBlenderService.Normal(background, foreground).ToRgb();   
    // Result: new RGB(211, 107, 184, 0.94);

    HEX resultHex = _colorBlenderService.Normal(background, foreground).ToHex();
    // Result: new HEX("d3", "6b", "b8", "ef");

    HSL resultHsl = _colorBlenderService.Normal(background, foreground).ToHsl();
    // Result: new HSL(315, 54, 62, 0.94);

    Color resultColor = _colorBlenderService.Normal(background, foreground).ToColor();
    // Result: new Color(211, 107, 184, 240) *;

    // Rounding the output value to 5 decimal places in the return value.
    URGB resultURgb = _colorBlenderService.Normal(background, foreground).ToUrgb(true, 5); 
    // Result: new URGB(0.82645, 0.41986, 0.72315, 0.94);
}

* This is not a proper way to create a system color. It is used here in this form only to display the result.

Notes

  • Powered by .NET Standart 2.0
  • Adobe Photoshop uses slightly different algoritm and rounding to perform color blending, which means that you won't get an identical result.
  • Might be bugs. Please submit an issue if you find one.

Thanks

Many thanks to:

Creative Society

We support Creative Society

Creative Society is a worldwide project of all humanity and it concerns everyone.

Project objectives

  • To create conditions for building a creative society on the whole planet by peaceful means.
  • To ask people all over the world whether they want to live in a creative society, and how they envisage it.
  • To provide a platform for a global, international, open discussion of the concept and model of the creative society in all spheres of human life.
  • To find new ways to unite the entire humanity and create conditions for the active participation of every person in the life of society, regardless of social status, religion or nationality.

Join us today!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 322 10/19/2022