如何将输入文本框的邮箱地址转变成图片?

解决方案 »

  1.   

    建一页面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=...">
      

  2.   

    说白了就是文字生成图片,要直接生成,而不是像<img src="eimg.aspx?email=...">这样去调用一个生成的页面。
    因为我们都是生成了静态页面,所以要静态的图片。
      

  3.   


                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..");//保存到文件