在.net中创建一个圆形头像图像 [英] Create a circle avatar image in .net
本文介绍了在.net中创建一个圆形头像图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个默认的头像图像,它是一个带有首字母的圆圈。我想在服务器端以png的身份执行此操作。这可能使用.net图形库吗?
I want to create a default avatar image which is a circle with initials in it. I want to do this on the server side as a png. Is this possible using the .net graphics library?
推荐答案
我最终这样做了。感谢您指引我朝着正确的方向TaW
I ended up doing this. Thanks for pointing me in the right direction TaW
public ActionResult Avatar()
{
using (var bitmap = new Bitmap(50, 50))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.Clear(Color.White);
using (Brush b = new SolidBrush(ColorTranslator.FromHtml("#eeeeee")))
{
g.FillEllipse(b, 0, 0, 49, 49);
}
float emSize = 12;
g.DrawString("AM", new Font(FontFamily.GenericSansSerif, emSize, FontStyle.Regular),
new SolidBrush(Color.Black), 10, 15);
}
using (var memStream = new System.IO.MemoryStream())
{
bitmap.Save(memStream, System.Drawing.Imaging.ImageFormat.Png);
var result = this.File(memStream.GetBuffer(), "image/png");
return result;
}
}
}
这篇关于在.net中创建一个圆形头像图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文