• Webform 上传图片加水印


    界面:

     1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
     2 
     3 <!DOCTYPE html>
     4 
     5 <html xmlns="http://www.w3.org/1999/xhtml">
     6 <head runat="server">
     7     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     8     <title></title>
     9     <style type="text/css">
    10         #Image1 {
    11              500px;
    12         }
    13     </style>
    14 </head>
    15 <body>
    16     <form id="form1" runat="server">
    17         <div>
    18             <asp:FileUpload ID="FileUpload1" runat="server" />
    19             <asp:Button ID="Button1" runat="server" Text="上传" />
    20             <br />
    21             <asp:Image ID="Image1" runat="server" />
    22         </div>
    23     </form>
    24 </body>
    25 </html>
    界面

    后台:

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 using System.Web.UI;
     6 using System.Web.UI.WebControls;
     7 using System.Drawing;
     8 
     9 public partial class _Default : System.Web.UI.Page
    10 {
    11     protected void Page_Load(object sender, EventArgs e)
    12     {
    13         Button1.Click += Button1_Click;
    14     }
    15 
    16     void Button1_Click(object sender, EventArgs e)
    17     {
    18         //画布
    19         System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent);
    20 
    21         Graphics g = Graphics.FromImage(img);
    22         //水印内容
    23         string s = "汉企奇点网络0928";
    24         Font f = new Font("微软雅黑",20);//字体
    25         Brush b = new SolidBrush(Color.Red);//颜色
    26         //所在画布位置
    27         PointF p = new PointF(20,20);
    28         PointF p1 = new PointF(100, 100);
    29         PointF p2 = new PointF(400, 100);
    30         PointF p3 = new PointF(250, 200);
    31 
    32         g.DrawString(s, f, b, p);
    33         g.DrawString(s, f, b, p1);
    34         g.DrawString(s, f, b, p2);
    35         g.DrawString(s, f, b, p3);
    36 
    37         string sss = "images/"+DateTime.Now.ToString("yyyyMMddhhmmssms")+FileUpload1.FileName;
    38         //保存位置
    39         img.Save(Server.MapPath(sss));
    40         //显示图片
    41         Image1.ImageUrl = sss;
    42     }
    43 }
    后台:

  • 相关阅读:
    同时使用gitee和github
    vim的四种模式及模式切换
    Vim使用入门
    Vim, Vim Diff, Vim Easy, Vim Read-only 区别
    公钥与私钥
    Linux使用Aria2命令下载BT种子/磁力/直链文件
    Content-Type /AJAX /@ResponseBody
    IDEA 添加serialVersionUID 检查
    Servlet中的Context Path | Servlet Path | Path Info
    第K大的数
  • 原文地址:https://www.cnblogs.com/maxin991025-/p/6256487.html
Copyright © 2020-2023  润新知