- 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());
来源: http://www.phpxs.com/code/1004382/