zoukankan      html  css  js  c++  java
  • WebForm水印照片

    水印照片需要的元素

    绘制:
    1、画布
    2、画笔 样式 粗细 颜色
    3、画什么东西
    4、用什么字体画 大小
    5、位置

    展示页面

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <style>
            #Image1 {
            300px;
            height:300px;
            
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:Button ID="Button1" runat="server" Text="上传" />
            <asp:Image ID="Image1"  runat="server" />
        </div>
        </form>
    </body>
    </html>
    View Code

    代码面

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Drawing;
    
    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)
        {
    
            //绘制画布:接收FileUpload1选中的图片,图片即画布
            System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent);
    
            //创建绘制对象,告诉它在哪张照片进行绘制
            Graphics g = Graphics.FromImage(img);
            //绘制文本内容
            string s = "这是一张照片";
            //绘制文本画刷和画刷颜色
            Brush b = new SolidBrush(System.Drawing.Color.Red);
            //绘制文本字体和大小
            Font f = new Font("宋体", 30);
            //开始绘制文本
            g.DrawString(s,f,b,50,50);
            //设置水印后的图片的相对路径和名字  image文件夹与Default平级
            string path = "image/"+DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒")+FileUpload1.FileName;
            //保存照片
            img.Save(Server.MapPath(path));
            //页面显示水印后的照片
            Image1.ImageUrl = path;
        }
    }
    View Code

    完!!

  • 相关阅读:
    算法竞赛入门经典第一章习题解答
    程序实现求int类型和double类型的最大最小值范围
    程序实现求int类型和double类型的最大最小值范围
    程序实现求int类型和double类型的最大最小值范围
    程序实现求int类型和double类型的最大最小值范围
    机器狗组装费用 南邮NOJ 1076 优先权队列
    【HDOJ】2604 Queuing
    【HDOJ】1208 Pascal's Travels
    【HDOJ】4857 逃生
    【HDOJ】2510 符号三角形
  • 原文地址:https://www.cnblogs.com/wwz-wwz/p/6077354.html
Copyright © 2011-2022 走看看