博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2017-6-8 上传图片加水印,验证码制作
阅读量:5812 次
发布时间:2019-06-18

本文共 3722 字,大约阅读时间需要 12 分钟。

1、上传图片加水印:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

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)    {        //获得要上传的图片        System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent);        //加上水印        Graphics g = Graphics.FromImage(img);        string s="hello word";        Font f=new Font("微软雅黑",30);        Brush b=new SolidBrush(Color.Red);        PointF pf=new PointF(50,50);        g.DrawString(s,f,b,pf);        //保存下来        string path = "upload/" +DateTime.Now.ToString("yyyyMMddhhmmssms")+ FileUpload1.FileName;        img.Save(Server.MapPath(path));        Image1.ImageUrl = path;    }}

2、验证码制作

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

 

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 Default2 : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {               Button1.Click += Button1_Click;    }    void Button1_Click(object sender, EventArgs e)    {        Label1.Text = Session["Default2"].ToString();        if (TextBox1.Text == Session["Default2"].ToString())        {            Label2.Text = "正确!!!";        }        else { Label2.Text = "错误!!"; }    }}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="yzm.aspx.cs" Inherits="yzm" %>
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 yzm : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        List
clist = new List
(); clist.Add(Color.Red); clist.Add(Color.Purple); clist.Add(Color.Pink); clist.Add(Color.Blue); clist.Add(Color.Orange); clist.Add(Color.Black); clist.Add(Color.White); clist.Add(Color.Violet); Random r = new Random(); string s = ""; string all = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (int i = 0; i < 4; i++) { s += all.Substring(r.Next(0, all.Length), 1); } Session["Default2"] = s; Bitmap img = new Bitmap(100, 50); Graphics g = Graphics.FromImage(img); Brush b = new SolidBrush(clist[r.Next(0, clist.Count)]); g.FillRectangle(b, 0, 0, 100, 50); Graphics g2 = Graphics.FromImage(img); Font f = new Font("微软雅黑", 30); Brush b2 = new SolidBrush(Color.Red); PointF pf = new PointF(5, 5); g2.DrawString(s, f, b2, pf); for (int i = 0; i < 7; i++) { Graphics g3 = Graphics.FromImage(img); Pen p3 = new Pen(new SolidBrush(clist[r.Next(0, clist.Count)]), r.Next(2, 5)); g3.DrawLine(p3, new Point(r.Next(0, 100), r.Next(0, 50)), new Point(r.Next(0, 100), r.Next(0, 50))); } img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png); }}

 

转载于:https://www.cnblogs.com/zhengqian/p/6986280.html

你可能感兴趣的文章
An Introduction to Interactive Programming in Python (Part 1) -- Week 2_1 练习
查看>>
web打印总结
查看>>
Android 应用程序集成FaceBook 登录及二次封装
查看>>
JNDI绑定数据库
查看>>
Android实时取景:用SurfaceView实现
查看>>
微信小程序与传统APP十大优劣对比
查看>>
【案例】主从替换之后的复制风暴
查看>>
SAP 实时产品支持模式:Expert Chat 服务来了!
查看>>
自动升级系统OAUS的设计与实现(续) (附最新源码)
查看>>
Linux 系统健康巡检脚本
查看>>
Word如何设置单元格垂直居中
查看>>
八年前的烈士陵园游感
查看>>
AngularJS应用页面切换优化方案
查看>>
[20150717]备份变大.txt
查看>>
利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
查看>>
重构——61字段下移(Push Down Field)
查看>>
[20170619]11G expand sql text.txt
查看>>
Yarn源码分析之如何确定作业运行方式Uber or Non-Uber?
查看>>
信号槽库:sigslot.h和sigc++使用
查看>>
微信公众号运营架构图
查看>>