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

    完!!

  • 相关阅读:
    js eval函数写一个简单的计算器
    nginx方向代理
    nodejs环境的搭建(linux环境centos6.5)
    vue渲染数据后与owlCarousel轮播插件冲突,失效
    vue 配合vue-resource调用接口,获取数据
    高效生成随机数并去重
    nginx 调整配置文件支持TP框架
    noVNC 搭建
    python基础学习-socket1 初识socket
    python基础学习-面向对象-类的使用
  • 原文地址:https://www.cnblogs.com/wwz-wwz/p/6077354.html
Copyright © 2011-2022 走看看