zoukankan      html  css  js  c++  java
  • 上传图片加水印

    上传图片并显示:

    aspx中:

    <body>
        <form id="form1" runat="server">
        <div>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:Button ID="Button1" runat="server" Text="上传" /><br />
            <asp:Image ID="Image1" runat="server" />
        </div>
        </form>
    </body>

    cs中:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Click += Button1_Click;
        }
    
        void Button1_Click(object sender, EventArgs e)
        {
            string p = "pic/" + DateTime.Now.ToString("yyyyMMddhhmmssma") + FileUpload1.FileName;
            string path=Server.MapPath(p);
            FileUpload1.SaveAs(path);//绝对路径
            Image1.ImageUrl = p;//相对路径
        }
    }

    上传图片加水印:
    aspx与上相同;

    cs代码:添加using drawing类

    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Button1.Click += Button1_Click;
        }
    
        void Button1_Click(object sender, EventArgs e)
        {
            System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent);
    
            Graphics g = Graphics.FromImage(img);
    
            string s="汉企起点网络0928";
            Font f=new Font("宋体",20);
            Brush b=new SolidBrush(Color.Red);
            PointF p=new PointF(20,20);
    
            g.DrawString(s, f, b, p);
    
            string ss = "pic/" + DateTime.Now.ToString("yyyyMMddhhmmssms") + FileUpload1.FileName;
    
            img.Save(Server.MapPath(ss));
            Image1.ImageUrl = ss;
        }
    }
  • 相关阅读:
    解决object at 0x01DB75F0
    github导入文件操作
    git出现: not a git repository
    scrapy框架爬取妹子图片
    mysql触发器,视图,游标
    mysql锁
    在k-means或kNN,我们是用欧氏距离来计算最近的邻居之间的距离。为什么不用曼哈顿距离?
    数据库存储,索引,事务常见问题
    使用Request+正则抓取猫眼电影(常见问题)
    Tensorflow()
  • 原文地址:https://www.cnblogs.com/wy1992/p/6259427.html
Copyright © 2011-2022 走看看