//引入命名空间
//using System.Drawing;
//using System.Drawing.Drawing2D;
//using System.Drawing.Imaging;
//实例化Bitmap
Bitmap image = new Bitmap(300, 50);
//从bitmap实例创建Graphics实例
Graphics graphics = Graphics.FromImage(image);
//以黑色填充图片
graphics.Clear(Color.Black);
//定义绘制文字的字体和大小
Font font = new Font("宋体", 16);
//定义绘制文字的颜色
Brush brush = new SolidBrush(Color.White);
//绘制文字
graphics.DrawString("励志工作室", font, brush, 0, 0);
//释放Graphics对象
graphics.Dispose();
Response.Clear();
Response.ContentType = "image/pjpeg";
//将图片保存到Response的输出流中
image.Save(Response.OutputStream, ImageFormat.Jpeg);
//写入到Response输出流中
image.Dispose();
Response.End();
这篇博客介绍了如何利用GDI+在C#中创建一个Bitmap对象,填充背景色,设置字体和颜色来绘制文字,并将生成的图片保存为JPEG格式响应给用户。
2093

被折叠的 条评论
为什么被折叠?



