日期:2014-05-18 浏览次数:20498 次
建一页面eimg.aspx: page_load内: string emailstr = Request.QueryString["email"]; System.Drawing.Bitmap image = new System.Drawing.Bitmap(50, 18);//图片宽高,根据邮箱地址长高设 Graphics g = Graphics.FromImage(image); try { //清空图片背景色 g.Clear(Color.White); Font font = new System.Drawing.Font("宋体", 10, FontStyle.Regular); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.FromArgb(0x78FE8A3F), Color.FromArgb(0x78FE8A3F), 1.2f, true); g.DrawString(emailstr, font, brush, 5, 2); //画图片的边框线 g.DrawRectangle(new Pen(Color.FromArgb(0x78FE6903)), 0, 0, image.Width - 1, image.Height - 1); System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); Response.ClearContent(); Response.ContentType = "image/Gif"; Response.BinaryWrite(ms.ToArray()); } finally { g.Dispose(); image.Dispose(); } 调用: <img src="eimg.aspx?email=...">
------解决方案--------------------
System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); Response.ClearContent(); Response.ContentType = "image/Gif"; Response.BinaryWrite(ms.ToArray()); 不要了 =============> image.Save("filepath..");//保存到文件