📄 code.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Eallies.Site.Users
{
public partial class Code : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string code = this.GetCode();
this.CreateImage(code);
}
private string GetCode()
{
string code = Common.Function.GetRandomCode(5);
Session["Code"] = code;
return code;
}
private void CreateImage(string code)
{
Bitmap image = new Bitmap((int)Math.Ceiling((code.Length * 11.5)), 20);
Graphics print = Graphics.FromImage(image);
try
{
Random random = new Random();
print.Clear(Color.White);
for (int i = 0; i < 25; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
print.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}
Font font = new Font("Arial", 11, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, false);
print.DrawString(code, font, brush, 2, 2);
for (int i = 0; i < 25; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
print.DrawRectangle(new Pen(Color.FromArgb(127, 157, 185)), 0, 0, image.Width - 1, image.Height - 1);
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
}
finally
{
print.Dispose();
image.Dispose();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -