C# 文字动态转成图片

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

string str="hello";
Graphics g = Graphics.FromImage(new Bitmap(1, 1));
Font font=new Font("宋体", 9);
SizeF sizeF = g.MeasureString(str, font); //测量出字体的高度和宽度
Brush brush; //笔刷,颜色
brush = Brushes.Lime;
PointF pf = new PointF(0, 0);
Bitmap img = new Bitmap(Convert.ToInt32(sizeF.Width), Convert.ToInt32(sizeF.Height));
g = Graphics.FromImage(img);
g.DrawString(str, font, brush, pf);
//输出图片
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.BinaryWrite(ms.ToArray());