ToolBX.ColorFull 2.2.1

dotnet add package ToolBX.ColorFull --version 2.2.1
NuGet\Install-Package ToolBX.ColorFull -Version 2.2.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="ToolBX.ColorFull" Version="2.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToolBX.ColorFull --version 2.2.1
#r "nuget: ToolBX.ColorFull, 2.2.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 ToolBX.ColorFull as a Cake Addin
#addin nuget:?package=ToolBX.ColorFull&version=2.2.1

// Install ToolBX.ColorFull as a Cake Tool
#tool nuget:?package=ToolBX.ColorFull&version=2.2.1

ColorFull

ColorFull

A lightweight re-implementation of the color struct.

Why?

The color struct from .NET's System.Drawing is rather heavy when you really just want a container for red, green, blue and alpha values. This library aims to change that by providing easier to use methods and clearer names.

Game engines often re-implement this struct in their own way and this small package is meant to unify these implementations under a simpler type.

Getting started

You can use it the same way as System.Drawing.Color.

public void SomeShadyMethod()
{
    //Returns a color with red, green and blue values. Alpha is implicitly maxed out (255) by default
    var color1 = new Color(255, 255, 125);

    //Alpha is specified in this case 
    var color2 = new Color(68, 125, 200, 45);

    //You can also just use the initializer if you're one of those people who hate constructors. Omitting alpha also initializes it to 255 by default
    var color3 = new Color
    {
        Red = 250,
        Green = 128,
        Blue = 114
    };

    //Or you can also just specify it as well
    var color4 = new Color
    {
        Red = 250,
        Green = 128,
        Blue = 114,
        Alpha = 150
    };

    //Or if you really just want a red color with nothing else
    var color5 = new Color { Red = 255 };

    //If you liked color3 but wanted to adjust its blue value
    var color6 = color3 with { Blue = 189 };
}

Conversions

  • ToHtml : Converts your Color to an hexadecimal color code for use in HTML. Ex : color.ToHtml();
  • FromHtml : Takes an hexadecimal and converts it to an RGBA Color struct. Ex : Color.FromHtml("#FF5733");
  • Also contains an explicit convertor for ConsoleColor. Ex : var newColor = (ConsoleColor)color;

Compatibility with System.Drawing.Color

You can actually use it instead of System.Drawing.Color since it has an implicit conversion operator.

What that means is that whenever you use ColorFull.Color in a method that asks for System.Drawing.Color, .NET will automatically convert that ColorFull.Color to a System.Drawing.Color under the hood.

I wouldn't abuse it but it's there if you need it.

Did you seriously create a whole package just for a measly little struct?!

Yeah, I did. It might grow beyond that and include more eventually. Or not.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ToolBX.ColorFull:

Package Downloads
ToolBX.MisterTerminal

A high level library to easily and cleanly build smarter console applications.

ToolBX.DML.NET

.NET implementation of the Dialog Markup Language.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.1 443 1/13/2024
2.2.0-beta1 104 1/7/2024
2.0.3 206 6/19/2023
2.0.2 265 4/27/2023
2.0.1 290 12/3/2022
2.0.0 367 11/10/2022
2.0.0-beta2 118 10/3/2022
2.0.0-beta1 125 9/21/2022
1.0.5 410 9/21/2022
1.0.5-beta1 129 8/1/2022
1.0.4 415 7/17/2022
1.0.2 383 6/27/2022
1.0.1 659 5/9/2022
1.0.0 474 1/14/2022