ASP.NET生成IP签名图片

using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Web; 
using System.Web.SessionState; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.HtmlControls; 
using System.IO;

public partial class ErrorPage : System.Web.UI.Page
{
    private void Page_Load(object sender, System.EventArgs e)
    {
        string str = “heihei”;

        bool cusWord = false;

        //如果没有自定义文字则不显示,否则只显示前30位

        if ((str == null) || (str.Trim().Length == 0))
        {
            str = “”;
        }
        else
        {
            if (str.Length > 30)
            {
                str = str.Substring(0, 30) + “”;
            }
            string badword = “haha”;

            //过滤不健康词语

            for (int i = 0; i < badword.Split(‘|’).Length; i++)
            {
                str = str.Replace(badword.Split(‘|’)[i], “[脏话,已被过滤]”);
            }
            cusWord = true;
        }

        //获取来访者的相关信息

        string IP = “Your IP:” + Request.UserHostAddress;
        string Language = “Language:” + Request.UserLanguages[0];
        string OS = “Your Os:” + Request.Browser.Platform;
        string Browser = “Browser:” + Request.Browser.Browser + ” ” + Request.Browser.Version;

        //初始化一个Image对象

        System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Server.MapPath(“ip.jpg”));
        Graphics g = Graphics.FromImage(copyImage);
        g.DrawImage(copyImage, 0, 0, copyImage.Width, copyImage.Height);
        Font f = new Font(“courier new”, 8, System.Drawing.FontStyle.Bold);
        Font f1 = new Font(“宋体”, 9, System.Drawing.FontStyle.Underline);
        Brush b1 = new SolidBrush(Color.Blue);
        Brush b2 = new SolidBrush(Color.Red);
        Brush b3 = new SolidBrush(Color.Green);
        Brush b4 = new SolidBrush(Color.Black);

        if (cusWord)
        {

            g.DrawString(str, f1, b4, 80, 5);
            g.DrawString(IP, f, b1, 80, 18);
            g.DrawString(OS, f, b2, 80, 30);
            g.DrawString(Language, f, b2, 80, 42);
            g.DrawString(Browser, f, b3, 80, 54);

        }

        else
        {

            g.DrawString(IP, f, b1, 80, 10);
            g.DrawString(OS, f, b2, 80, 25);
            g.DrawString(Language, f, b2, 80, 40);
            g.DrawString(Browser, f, b3, 80, 55);

        }

        g.Dispose();
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        copyImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        Response.ClearContent();
        Response.ContentType = “image/Jpeg”;
        Response.BinaryWrite(ms.ToArray());
    }
}



本文固定链接: http://www.ntxz.net/?p=611 | 周忞 | 吉心的记事本



该日志由 吉心 于2010年02月12日发表在 懒得分类, 旧版博客 分类下, 你可以发表评论
在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: ASP.NET生成IP签名图片 | 周忞 | 吉心的记事本
【上一篇】
【下一篇】

ASP.NET生成IP签名图片:等您坐沙发呢!

发表评论

您必须 [ 登录 ] 才能发表留言!