zoukankan      html  css  js  c++  java
  • 图片加水印 图片验证码

    图片加水印

    1   获取这张图片

    System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent);

    2 给图片加水印

     Graphics g = Graphics.FromImage(img);        

    string s = "WWW.ITNBA.COM";         s 给图片加的水印文字

    Font f = new Font("微软雅黑", 30);        

    Brush b = new SolidBrush(Color.Red);        

    PointF pf = new PointF(50, 50);

            g.DrawString(s, f, b, pf);

    3 保存这张图

    string path = "Uploads/" + DateTime.Now.ToString("yyyyMMddhhmmssms") + FileUpload1.FileName;

           

    img.Save(Server.MapPath(path));        

    Image1.ImageUrl = path;

    网页保存这张图回事aspx格式   将后缀改成png格式即可查看图片

    小知识 :  图片转换成txt格式 会出现乱码  在乱码下方添加 文字 再转换成jpg个是不会影响图片

    图片格式的验证码

     List<Color> clist = new List<Color>();
            clist.Add(Color.Red);
            clist.Add(Color.Firebrick);
            clist.Add(Color.LawnGreen);
            clist.Add(Color.Goldenrod);
            clist.Add(Color.Cyan);
            clist.Add(Color.DarkSlateBlue);
            clist.Add(Color.Indigo);
            Random r = new Random();
            string s = "";
            string all = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmeopqrstuvwxyz0123456789";
            for (int i = 0; i < 4; i++)
            {
                s += all.Substring(r.Next(0, all.Length), 1);
            }
    
            Session["YZM"] = s;
    
            Bitmap img = new Bitmap(120, 60);
    
            Graphics g2 = Graphics.FromImage(img);
            Brush b2 = new SolidBrush(clist[r.Next(0, clist.Count)]);
            g2.FillRectangle(b2, 0, 0, 120, 60);
    
            Graphics g = Graphics.FromImage(img);
            Font f = new Font("微软雅黑", 30);
            Brush b = new SolidBrush(Color.Red);
    
            g.DrawString(s, f, b, new PointF(0, 0));
    
    
            for (int i = 0; i < 8; i++)
            {
                Graphics g3 = Graphics.FromImage(img);
                Pen p3 = new Pen(new SolidBrush(clist[r.Next(0, clist.Count)]), r.Next(2, 5));
                g3.DrawLine(p3, new Point(r.Next(0, 120), r.Next(0, 60)), new Point(r.Next(0, 120), r.Next(0, 60)));
            }
    
    
            img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
    图片后台

    前台验验证 验证码
    var a = 0;
        document.getElementById("yzm1").onclick = function () {
            this.src = "yzm.aspx?a=" + a;
            a++;
        }

    点击图片  切换验证码    方正验证码 图片重复  打开的验证码图片 传个值  这个值用不到

    就可以实现  图片 无限刷新

    toUpperCase  实现验证码大小写转换

  • 相关阅读:
    整理ASP.NET MVC 5各种错误请求[401,403,404,500]的拦截及自定义页面处理实例
    Sql Server 创建表添加说明
    c# 去除字符串中重复字符
    WebStorm中常用的快捷键及使用技巧
    git bash中的快捷键
    git bash here 的 ~/.bashrc 配置文件。和 vue/cli 3. 0 的 .vuerc文件(preset )
    右键菜单添加打开CMD选项
    Vue中使用Vue.component定义两个全局组件,用单标签应用组件时,只显示一个组件的问题和 $emit的使用。
    vue和stylus在subline中显示高亮
    stylus入门教程,在webstorm中配置stylus
  • 原文地址:https://www.cnblogs.com/v587yy/p/6971356.html
Copyright © 2011-2022 走看看