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 {
        width: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>

代码面

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 = );
        //开始绘制文本
        g.DrawString(s,f,b,,);
        //设置水印后的图片的相对路径和名字  image文件夹与Default平级
        string path = "image/"+DateTime.Now.ToString("yyyy年MM月dd日hh时mm分ss秒")+FileUpload1.FileName;
        //保存照片
        img.Save(Server.MapPath(path));
        //页面显示水印后的照片
        Image1.ImageUrl = path;
    }
}

完!!


C#中使用DrawString绘制文本时的对齐方式

void 绘制文字(Graphics 画家)
{
   StringFormat 格式 = new StringFormat();
   格式.Alignment = StringAlignment.Center; //居中
   格式.Alignment = StringAlignment.Far; //右对齐
   string 文本 = "";
   Rectangle 矩形 = new Rectangle(0, 0, 200, 200);
   Font 字体 = new Font("宋体", 10.5F);
   Brush 画笔 = Brushes.Blue;
   画家.DrawString(文本, 字体, 画笔, 矩形, 格式);
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值