More and more I am seeing companies set a user's default profile picture as shown in the screenshot below which is from the Google homepage...
How have Google achieved this?
In the top right hand corner of the Teams screen, there is a circle containing your initials (by default) or a photo. If you click on this, you will get your personal options (Settings).
When logging into your account on Teams, some of you may notice your initials in place of where your profile picture should be. If your profile picture shows your initial in Teams, then chances are that you are yet to upload a picture to be set as your profile photo on Microsoft Teams.
Click File > Options. In the Options dialog box, change your user name and initials in the Personalize your copy of Microsoft Office section.
Simple use .Net basic libraries. You can change in it as per your requirement. basic purpose is for creating user Profile Avatar image if user not use specific image for profile default image will be use. Two common types of images we need be made Rectangle & Circle.
For Circle Image
public MemoryStream GenerateCircle(string firstName, string lastName)
{
var avatarString = string.Format("{0}{1}", firstName[0], lastName[0]).ToUpper();
var randomIndex = new Random().Next(0, _BackgroundColours.Count - 1);
var bgColour = _BackgroundColours[randomIndex];
var bmp = new Bitmap(192, 192);
var sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
var font = new Font("Arial", 72, FontStyle.Bold, GraphicsUnit.Pixel);
var graphics = Graphics.FromImage(bmp);
graphics.Clear(Color.Transparent);
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
using (Brush b = new SolidBrush(ColorTranslator.FromHtml("#" + bgColour)))
{
graphics.FillEllipse(b, new Rectangle(0, 0, 192, 192));
}
graphics.DrawString(avatarString, font, new SolidBrush(Color.WhiteSmoke), 95, 100, sf);
graphics.Flush();
var ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Png);
return ms;
}
For Rectangle image :
public MemoryStream GenerateRactangle(string firstName, string lastName)
{
var avatarString = string.Format("{0}{1}", firstName[0], lastName[0]).ToUpper();
var randomIndex = new Random().Next(0, _BackgroundColours.Count - 1);
var bgColour = _BackgroundColours[randomIndex];
var bmp = new Bitmap(192, 192);
var sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
var font = new Font("Arial", 72, FontStyle.Bold, GraphicsUnit.Pixel);
var graphics = Graphics.FromImage(bmp);
graphics.Clear((Color)new ColorConverter().ConvertFromString("#" + bgColour));
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
graphics.DrawString(avatarString, font, new SolidBrush(Color.WhiteSmoke), new RectangleF(0, 0, 192, 192), sf);
graphics.Flush();
var ms = new MemoryStream();
bmp.Save(ms, ImageFormat.Png);
return ms;
}
For generating background random colors can be use :
private List<string> _BackgroundColours = new List<string> { "339966", "3366CC", "CC33FF", "FF5050" };
i hope it will help your,please pass your suggestions to improve it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With