第四种/RandImage.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;

namespace 验证码.第四种
{
    public class RandImage
    {
        private const string RandCharString = "0123456789";
        private int width;
        private int height;
        private int length;
        /// <summary>
        /// 默认构造函数,生成的图片宽度为48×24,随即字符串字符个数
        /// </summary>
        public RandImage():this(48,24,4)
        {
        }
        /// <summary>
        /// 指定生成图片的宽和高,默认生成图片的字符串长度为4个字符
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public RandImage(int width, int height):this(width,height,4)
        {
        }
        /// <summary>
        /// 指定生成图片的宽和高以及生成图片的字符串字符个数
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="length"></param>
        public RandImage(int width, int height, int length)
        {
            this.width = width;
            this.height = height;
            this.length = length;
        }
        /// <summary>
        /// 以默认的大小和默认的字符个数产生图片
        /// </summary>
        /// <returns></returns>
        public Image GetImage()
        {
            Bitmap image = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(image);
            g.Clear(Color.White);
            string randString = "";
            Random random=new Random();
            do
            {
//使用DateTime.Now.Millisecond作为生成随机数的参数,增加随机性
                randString += RandCharString.Substring(random.Next(DateTime.Now.Millisecond)%RandCharString.Length, 1);
            }
            while (randString.Length < 4);
            float emSize=(float)width/randString.Length;
            Font font = new Font("Arial", emSize, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
            Pen pen = new Pen(Color.Silver);
后面还有 30 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。