ToolBX.ColorFull 3.0.0

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

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

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 net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.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.DML.NET

.NET implementation of the Dialog Markup Language.

ToolBX.MisterTerminal

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

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 1,144 9/26/2024
3.0.0-beta1 119 9/23/2024
2.2.1 838 1/13/2024
2.2.0-beta1 144 1/7/2024
2.0.3 245 6/19/2023
2.0.2 316 4/27/2023
2.0.1 322 12/3/2022
2.0.0 417 11/10/2022
2.0.0-beta2 143 10/3/2022
2.0.0-beta1 157 9/21/2022
1.0.5 450 9/21/2022
1.0.5-beta1 155 8/1/2022
1.0.4 446 7/17/2022
1.0.2 414 6/27/2022
1.0.1 700 5/9/2022
1.0.0 534 1/14/2022