C# color helpers - color blender.
What's the resulting color of #AABBCC with 70% opacity on a white background?
That's what this library is for!
DarkColors is available using nuget. To install DarkColors, run the following command in the Package Manager Console
PM> Install-Package Divis.DarkColors
Blend multiple colors together with transparency support.
//The base color. This one can't be transparent. If it is, the alpha channel will be ignored.
var baseColor = Color.FromArgb(0, 0, 0);
//A color to add. This one can have transparency.
var colorToAdd = Color.FromArgb(125, 55, 13);
var twoColorsCombined = ColorBlender.Combine(baseColor, colorToAdd);
//The base color. This one can't be transparent. If it is, the alpha channel will be ignored.
var baseColor = Color.FromArgb(0, 0, 0);
//A color to add. This one can have transparency.
var colorToAdd = Color.FromArgb(127, 125, 55, 13);
//The color's amount is set to 50% and it's alpha channel is at 50% so in the result, only 25% of this color will be added on top of the base color.
var colorToAddLayer = new ColorLayer(colorToAdd, 50);
var twoColorsCombined = ColorBlender.Combine(baseColor, colorToAddLayer);
var anotherColorToAdd = Color.FromArgb(255, 13, 79);
var anotherColorToAddLayer = new ColorLayer(anotherColorToAdd, 25);
var threeColorsCombined = ColorBlender.Combine(baseColor, colorToAddLayer, anotherColorToAddLayer);
Using the Color
's alpha channel:
var baseColor = Color.FromArgb(0, 0, 0);
//set 50% transparency using the color Alpha channel
var colorToAdd = Color.FromArgb(127, 125, 55, 13);
var twoColorsCombined = ColorBlender.Combine(baseColor, colorToAdd);
Using the ColorLayer
's AmountPercentage
property:
var baseColor = Color.FromArgb(0, 0, 0);
var colorToAdd = Color.FromArgb(125, 55, 13);
//set 50% transparency using the color AmountPercentage property of the ColorLayer
var colorToAddLayer = new ColorLayer(colorToAdd, 50);
var twoColorsCombined = ColorBlender.Combine(baseColor, colorToAdd);
Using both the Color
's alpha channel and ColorLayer
's AmountPercentage
property:
var baseColor = Color.FromArgb(0, 0, 0);
//set 50% transparency using the color Alpha channel
var colorToAdd = Color.FromArgb(127, 125, 55, 13);
//set 50% transparency using the color AmountPercentage property of the ColorLayer. The resulting color will only be added by 25% because both color's Alpha and layer's AmountPercentage were used.
var colorToAddLayer = new ColorLayer(colorToAdd, 50);
var twoColorsCombined = ColorBlender.Combine(baseColor, colorToAdd);
var baseColor = Color.FromArgb(0, 0, 0);
var colorToAdd = Color.FromArgb(125, 55, 13);
var twoColorsCombined = baseColor.Combine(colorToAdd);
Find dominant color in an image.
//array of pixels that represents an image
Color[] pixels;
//returns a list of dominant color candidates, ordered by probability
List<DominantColorCandidate> candidates = ColorAnalyzer.FindDominantColors(pixels);
Color[] pixels;
List<DominantColorCandidate> candidates = ColorAnalyzer.FindDominantColors(pixels, options =>
{
options.MinSaturation = 0.4f,
options.MinSpaceCoverage = 0.05f,
options.ColorGrouping = 0.3f
});