IdenticonStyle Class

Specifies the color style of an identicon.
public class IdenticonStyle : IEquatable<IdenticonStyle>
View source
Namespace
Jdenticon
Package
PackageJdenticon-net
Inheritance
SystemObject JdenticonIdenticonStyle

Remarks

This class is used to customize the colors of generated icons. You can use the icon designer to simplify finding good values.

Individual icons

Individual icons are styled by setting the Style property of an Identicon instance.

Styling an individual icon
var icon = Identicon.FromValue("string to hash", size: 100);
icon.Style = new IdenticonStyle 
{
    Hues = new HueCollection { { 207, HueUnit.Degrees } },
    BackColor = Color.FromRgba(42, 71, 102, 255),
    ColorLightness = Range.Create(0.84f, 0.84f),
    GrayscaleLightness = Range.Create(0.84f, 0.84f),
    ColorSaturation = 0.48f,
    GrayscaleSaturation = 0.48f
};
icon.SaveAsPng("test.png");

Default style

A default style can be created by setting the Identicon.DefaultStyle property. You can still override the style of individual icons with Identicon.Style. This approach is suitable for most cases, including ASP.NET.

Note Note
The Identicon.DefaultStyle property is not supported by IdenticonElement. Instead create a WPF style setting the correspnding style properties directly on IdenticonElement.
Setting a default style
Identicon.DefaultStyle = new IdenticonStyle 
{
    Hues = new HueCollection { { 207, HueUnit.Degrees } },
    BackColor = Color.FromRgba(42, 71, 102, 255),
    ColorLightness = Range.Create(0.84f, 0.84f),
    GrayscaleLightness = Range.Create(0.84f, 0.84f),
    ColorSaturation = 0.48f,
    GrayscaleSaturation = 0.48f
};

Identicon.FromValue("string to hash", size: 100).SaveAsPng("test.png");

WPF

In WPF the recommended way of styling an icon is by creating a WPF style setting style properties on IdenticonElement. You can also set an IdenticonStyle by using the IdenticonElement.IdenticonStyle property.

WPF identicon with custom style
<Window x:Class="SampleApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:jd="clr-namespace:Jdenticon.Wpf;assembly=Jdenticon.Wpf"
        Title="MainWindow" Height="250" Width="600">
    <Window.Resources>
        <Style TargetType="{x:Type jd:IdenticonElement}">
            <Setter Property="Width" Value="100" />
            <Setter Property="Height" Value="100" />
            <Setter Property="Margin" Value="10" />

            <!-- Custom identicon style -->
            <!-- https://jdenticon.com/icon-designer.html?config=2a4766ff10cf303054545454 -->
            <Setter Property="Hues" Value="207deg"/>
            <Setter Property="Background" Value="#2a4766"/>
            <Setter Property="ColorLightness" Value="0.84, 0.84"/>
            <Setter Property="GrayscaleLightness" Value="0.84, 0.84"/>
            <Setter Property="ColorSaturation" Value="0.48"/>
            <Setter Property="GrayscaleSaturation" Value="0.48"/>
        </Style>
    </Window.Resources>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <jd:IdenticonElement Value="icon1" />
        <jd:IdenticonElement Value="icon2" />
        <jd:IdenticonElement Value="icon3" />
        <jd:IdenticonElement Value="icon4" />
    </StackPanel>
</Window>

Here is what the icons above look like:

Identicons with custom style

Windows Forms

You can affect the style by setting the style properties directly on IdenticonView.

Styling Windows Forms

Another option is to use the IdenticonView.Style property.

Constructors

Public methodIdenticonStyle
Creates a new IdenticonStyle instance initialized with the default values of each property.

Properties

Public propertyBackColor
The background color of the icon. Set to Transparent to remove the background. Default value is white.
Public propertyColorLightness
The lightness range of the colored shapes in the icon. Default value is 0.4f - 0.8f.
Public propertyColorSaturation
The saturation of the colored shapes in the icon. Valid values are [0.0f, 1.0f]. Default value is 0.05f.
Public propertyStatic memberDefaultBackColor
Gets the default value of the BackColor property. Resolves to White.
Public propertyStatic memberDefaultColorLightness
Gets the default value of the ColorLightness property. Resolves to [0.4f, 0.8f].
Public propertyStatic memberDefaultColorSaturation
Gets the default value of the ColorSaturation property. Resolves to 0.5f.
Public propertyStatic memberDefaultGrayscaleLightness
Gets the default value of the GrayscaleLightness property. Resolves to [0.3f, 0.9f].
Public propertyStatic memberDefaultGrayscaleSaturation
Gets the default value of the GrayscaleSaturation property. Resolves to 0f.
Public propertyStatic memberDefaultPadding
Gets the default value of the Padding property. Resolves to 0.08f.
Public propertyGrayscaleLightness
The lightness range of the grayscale shapes in the icon. Default value is 0.3f - 0.9f.
Public propertyGrayscaleSaturation
The saturation of the by default grayscale shapes in the icon. The same hue is used for colored and grayscale shapes. Valid values are [0.0f, 1.0f]. Default value is 0f.
Public propertyHues
Gets or sets a collection of the allowed hues in the generated icons. If the collection is empty all hues are allowed.
Public propertyPadding
Gets or sets the padding between the edge of the image and the bounds of the rendered icon. The value is specified in percent in the range [0.0, 0.4]. Default value is 0.08f.

Methods

Public methodClone
Creates and returns a deep copy of this IdenticonStyle.
Public methodEquals(Object)
Checks if this style is identical to another style.
Public methodEquals(IdenticonStyle)
Checks if this style is identical to another style.
Public methodGetHashCode
Gets a hash code for this IdenticonStyle.

See Also

Reference