博客
关于我
强烈建议你试试无所不能的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

你可能感兴趣的文章
Spring ’14 Wave Update: Installing Dynamics CRM on Tablets for Windows 8.1
查看>>
MySQL 备份与恢复
查看>>
TEST
查看>>
PAT A1037
查看>>
(六)Oracle学习笔记—— 约束
查看>>
[Oracle]如何在Oracle中设置Event
查看>>
top.location.href和localtion.href有什么不同
查看>>
02-创建hibernate工程
查看>>
Scrum之 Sprint计划会议
查看>>
svn命令在linux下的使用
查看>>
Gradle之module间依赖版本同步
查看>>
java springcloud版b2b2c社交电商spring cloud分布式微服务(十五)Springboot整合RabbitMQ...
查看>>
10g手动创建数据库
查看>>
Windwos Server 2008 R2 DHCP服务
查看>>
UVa 11292 勇者斗恶龙(The Dragon of Loowater)
查看>>
白话算法(7) 生成全排列的几种思路(二) 康托展开
查看>>
d3 v4实现饼状图,折线标注
查看>>
微软的云策略
查看>>
Valid Parentheses
查看>>
【ES6】数值的扩展
查看>>