/avataaarsnet

.NET Porting of fangpenlin/avaaatars-generator

Primary LanguageC#MIT LicenseMIT

AvataaarsNet - The .NET Component for Avataaars

This is a WPF Component porting of Avataaars Generator by Fang-Pen Lin.

Features

  • Built on top of .NET Framework 4.7.2
  • Uses the https://avataaars.io endpoint for generate the images (can also be self-hosted, see below)

Usage

demo

Add the reference to the namespace AvataaarsNet in your project and in your XAML.

xmlns:avataaarsnet="clr-namespace:AvataaarsNet;assembly=AvataaarsNet"

Add the component in your XAML (typical implementation, may vary based on purposes)

<avataaarsnet:AvataaarsGenerator
  x:Name="Avataaaars"
  Avatar="{Binding Path=Avatar, ElementName=MyWindow, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
  Configuration="{Binding Path=Configuration, ElementName=MyWindow, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
  EnableWidth="{Binding Path=EnableWidth, ElementName=MyWindow, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />

It exposes three DependencyProperty:

Avatar is the resulting Bitmap (OneWayToSource) image based upon the actual configuration.

Configuration is the binding (TwoWay) of an AvataaarsConfiguration object that contains all the parameters to generate the image (can be used to save the configuration and restore it later).

EnableWidth is the binding (OneWay) to show or hide the custom Width parameter (default value is 512px).

Randomize

This library provides a usefull Randomize function to generate a Configuration object to bind to the control.
Just use

AvataaarsSettings.Randomize(uint width)

and bind the return to the configuration property.

Demo

A working demo can be found on my other repository here.
There is no nuget package so you need to add this project to the solution or compile the .dll and add it as a reference.

Self-hosted server side rendering

Special thanks to @gkoberger for porting the React component server side and deploying it to https://avataaars.io
This can also be self-hosted, refer to its repository for further details.

Another simple way to host it by yourself, with Avataaars React package updated to v1.2.1, minor improvements and no AWS storage, is to follow my fork here.

NB: When self hosted you simply need to change the baseUrl value in the Avataaars class to call the correct endpoint.