试试: private void ConvertStringToImage(HttpContext context, string outputString, int width, int height, Color color) { Bitmap image = new Bitmap(width, height); Graphics g = Graphics.FromImage(image); Font font = new Font("SimHei", 24, FontStyle.Bold); SolidBrush brush = new SolidBrush(color); g.Clear(Color.White); StringFormat format = new StringFormat(); g.DrawString(outputString, font, brush, 0, 0, format); System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); context.Response.ClearContent(); context.Response.ContentType = "image/pjpeg"; //image/gif context.Response.BinaryWrite(ms.ToArray()); }
{
Bitmap image = new Bitmap(width, height);
Graphics g = Graphics.FromImage(image);
Font font = new Font("SimHei", 24, FontStyle.Bold);
SolidBrush brush = new SolidBrush(color);
g.Clear(Color.White);
StringFormat format = new StringFormat();
g.DrawString(outputString, font, brush, 0, 0, format);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); context.Response.ClearContent();
context.Response.ContentType = "image/pjpeg"; //image/gif
context.Response.BinaryWrite(ms.ToArray());
}