ASP.NET 画图与图像处理-写字与画线

作者:vkvi 来源:ITPOW(原创) 日期:2007-8-30
Bitmap srcImg = new Bitmap(300, 300); //也可以读入一张图片
Graphics graphics = Graphics.FromImage(srcImg);

Font font = new Font("宋体", 16); //字体与大小
Brush brush = new SolidBrush(Color.Red);
graphics.DrawString("www.itpow.com", font, brush, 50, 50); //写字,最后两个参数表示位置

Pen pen = new Pen(Color.FromArgb(33, 66, 99), 10); //颜色与宽度
Point[] pts = new Point[3]; //曲线的点
pts[0] = new Point(120, 130);
pts[1] = new Point(140, 280);
pts[2] = new Point(200, 100);
graphics.DrawCurve(pen, pts); //画曲线

srcImg.Save(Server.MapPath("example.jpg"));

graphics.Dispose();
srcImg.Dispose();

Bitmap、Graphics 的名称空间是

System.Drawing

Graphics 画图功能强大,以上只是示例,但其它画直线、画弧、画饼等等功能都不复杂。

通过该示例,我们就可以在 ASP.NET 中轻松实现验证码了。

相关阅读

相关文章