您现在的位置是:网站首页> 编程资料编程资料
Asp.net开发之webform图片水印和图片验证码的实现方法_实用技巧_
2023-05-24
166人已围观
简介 Asp.net开发之webform图片水印和图片验证码的实现方法_实用技巧_
两者都需要引入命名空间:using System.Drawing;
一、图片水印
前台Photoshuiyin.aspx代码:
后台Photoshuiyin.aspx.cs代码:
protected void Page_Load(object sender, EventArgs e) { Button1.Click += Button1_Click; } void Button1_Click(object sender, EventArgs e) { //1、制作画布 System.Drawing.Image img = System.Drawing.Image.FromStream(FileUpload1.FileContent); Graphics g = Graphics.FromImage(img); //水印样式:画什么东西 string a = "http://www.itnba.com"; //字体、大小 Font f = new Font("黑体", 30); //颜色 Brush b = new SolidBrush(Color.Red); //0,0——开始画水印的位置 g.DrawString(a, f, b, 0, 0); //保存路径 string path = "images/" + FileUpload1.FileName; img.Save(Server.MapPath(path)); //在image控件中展示 Image1.ImageUrl = path; }效果展示:

二、图片验证码
前台Photoyanzhengma.aspx代码: