NetPalette 0.0.2

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

// Install NetPalette as a Cake Tool
#tool nuget:?package=NetPalette&version=0.0.2                

<img src="" width="320px" />

NetPalette 🎨

.NET alternate text is missing from this package README image alternate text is missing from this package README image

A Library for generating color palettes from images - powered by SkiaSharp so it can be used in any modern .NET UI framework. Inspired by the Android Palette API


There is a .NET MAUI app in /Samples which demonstrates palette generation for random Unsplash images. The library is not limited to MAUI, it can be used in any .NET UI framework like Uno, Avalonia, WinUI, WPF, etc. any framework that supports SkiaSharp.


Palette Generation

To generate a palette from a bitmap image, you can use the FromBitmap method of the PaletteGenerator class. This method takes in various parameters to customize the palette generation process

using SkiaSharp;

// Load your bitmap image
SKBitmap bitmap = SKBitmap.Decode("path/to/your/image.png");

// Define region of interest if necessary - this is optional
SKRect region = new SKRect(0, 0, bitmap.Width, bitmap.Height); // Entire image

// Optionally define palette filters - this is optional
List<IPaletteFilter> filters = new List<IPaletteFilter> { new AnyPaletteFilter() };

// Optionally define palette targets - this is optional
List<PaletteTarget> targets = new List<PaletteTarget> { PaletteTarget.Vibrant, PaletteTarget.DarkMuted };

// Generate the palette
PaletteGenerator paletteGenerator = PaletteGenerator.FromBitmap(bitmap, maximumColorCount: 16, region, filters, targets, fillMissingTargets: true);

// Access the generated palette colors
SKColor vibrantColor = paletteGenerator.VibrantColor.Color;
SKColor darkMutedColor = paletteGenerator.DarkMutedColor.Color;

// Iterate over all quantized colors
foreach (SKColor color in paletteGenerator.Colors)
    // Do something with each color

Accessing Generated Palette Colors

You can access the generated palette colors using the properties provided by the PaletteGenerator instance.

// Accessing specific palette colors
SKColor vibrantColor = paletteGenerator.VibrantColor.Color;
SKColor lightVibrantColor = paletteGenerator.LightVibrantColor.Color;
SKColor darkVibrantColor = paletteGenerator.DarkVibrantColor.Color;
SKColor mutedColor = paletteGenerator.MutedColor.Color;
SKColor lightMutedColor = paletteGenerator.LightMutedColor.Color;
SKColor darkMutedColor = paletteGenerator.DarkMutedColor.Color;
SKColor dominantColor = paletteGenerator.DominantColor.Color;

// Iterate over palette colors
foreach (SKColor color in paletteGenerator.PaletteColors)
    // Do something with each palette color

// Iterate over all quantized colors
foreach (SKColor color in paletteGenerator.Colors)
	// Do something with each color


Create a PaletteGenerator instance using the FromBitmap method of the PaletteGenerator class. This method takes in the following parameters:

  • encodedImage (SKBitmap): The bitmap image from which to generate the palette.

  • maximumColorCount (int, optional): The maximum number of colors to include in the palette. Default is 16.

  • region (SKRect, optional): The region of interest within the image. Default is the entire image.

  • filters (List<IPaletteFilter>, optional): Optional palette filters to apply during palette generation.

  • targets (List<PaletteTarget>, optional): Optional palette targets to specify which colors to select from the generated palette.

  • fillMissingBaseTargets (bool, optional): Specifies whether to fill missing base targets in the selected swatches. Default is false.


A PaletteGenerator instance containing the generated palette.

  • ArgumentOutOfRangeException: Thrown when the specified region is outside the bounds of the image.

  • ArgumentException: Thrown when the image byte data doesn't match the image size or has invalid encoding.

not finalized yet

please note that the API is not finalized yet and might change in the future. If you have any suggestions or feature requests, feel free to open an issue or a pull request.


most of the code is based on the palette_generator package from the Flutter SDK - credits to the original authors of that code. Great kudos also to the SkiaSharp contributors for providing such a great library 👏

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.0.2 124 5/8/2024
0.0.1 66 5/8/2024