KlxPiao.ColorTool
0.0.4
dotnet add package KlxPiao.ColorTool --version 0.0.4
NuGet\Install-Package KlxPiao.ColorTool -Version 0.0.4
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="KlxPiao.ColorTool" Version="0.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KlxPiao.ColorTool" Version="0.0.4" />
<PackageReference Include="KlxPiao.ColorTool" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KlxPiao.ColorTool --version 0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: KlxPiao.ColorTool, 0.0.4"
#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.
#:package KlxPiao.ColorTool@0.0.4
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KlxPiao.ColorTool&version=0.0.4
#tool nuget:?package=KlxPiao.ColorTool&version=0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
KlxPiao.ColorTool
A simple and easy-to-use color space conversion tool that supports mutual conversion between HSL/HSV and RGB color spaces.
Preview
Installation
Install-Package KlxPiao.ColorTool
Usage (Similarly for Hsv)
1️⃣ Convert HSL to Color
// Method 1: Implicit conversion via HslColor
var hsl = HslColor.FromHsl(0, 1, 1); // Using float parameters (H: 0-360°, S/L: 0-1)
Color color1 = hsl; // Implicit conversion to Color
// Method 2: Direct creation from string
var hsl2 = HslColor.FromString("0, 100%, 100%");
Color color2 = hsl2; // Implicit conversion to Color
// Method 3: Quick methods (no explicit instantiation)
Color color3 = HslColor.FromHsl(0, 1, 1);
Color color4 = HslColor.FromString("0, 100%, 100%");
2️⃣ Convert Color to HSL
// Get HSL values via implicit conversion
HslColor hsl = Colors.Red; // Implicit conversion to HslColor
float h = hsl.Hue; // Output: 0f (0-360 range)
float s = hsl.Saturation; // Output: 1f (0-1 range)
float l = hsl.Lightness; // Output: 1f (0-1 range)
// Get string representation
string hslString1 = hsl.ToString(); // Output: "0, 100%, 100%"
// Get string via extension method
string hslString2 = Colors.Red.ToHslString(); // Output: "0, 100%, 100%"
📝 Notes
- Parameter Ranges:
FromHsl()acceptsHue: 0-360,Saturation/Lightness: 0-1FromString()requires format:"H, S%, L%"
- Compatibility:
- Supports both spaced (e.g.,
"0, 100%, 50%") and unspaced (e.g.,"0,100%,50%") formats - Parameters are automatically clamped to valid ranges (e.g., 1.5 → 1.0, 721 → 1)
- When S/L values include '%', the symbol is removed and divided by 100. Without '%', values remain unchanged.
- Supports both spaced (e.g.,
- Implicit Conversion Equivalence:
- Implicit conversion is equivalent to
color.ToHsl()orhslColor.ToColor()
- Implicit conversion is equivalent to
- Exception Handling:
- Invalid strings throw
FormatException
- Invalid strings throw
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0-windows7.0 is compatible. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0-windows7.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.