随机图片生成器制作方法分享(2)

/// <summary>
    /// 英文与数字串
    /// </summary>
    protected static readonly string EnglishOrNumChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

public VryImgGen()
    {
        rnd = new Random(unchecked((int)DateTime.Now.Ticks));
    }

/// <summary>
    /// 全局随机数生成器
    /// </summary>
    private Random rnd;

int length = 5;
    /// <summary>
    /// 验证码长度(默认6个验证码的长度)
    /// </summary>
    public int Length
    {
        get { return length; }
        set { length = value; }
    }

int fontSize = 20;
    /// <summary>
    /// 验证码字体大小(为了显示扭曲效果,默认30像素,可以自行修改)
    /// </summary>
    public int FontSize
    {
        get { return fontSize; }
        set { fontSize = value; }
    }

int padding = 4;
    /// <summary>
    /// 边框补(默认4像素)
    /// </summary>
    public int Padding
    {
        get { return padding; }
        set { padding = value; }
    }

bool chaos = true;
    /// <summary>
    /// 是否输出燥点(默认输出)
    /// </summary>
    public bool Chaos
    {
        get { return chaos; }
        set { chaos = value; }
    }

Color chaosColor = Color.LightGray;
    /// <summary>
    /// 输出燥点的颜色(默认灰色)
    /// </summary>
    public Color ChaosColor
    {
        get { return chaosColor; }
        set { chaosColor = value; }
    }

int chaosWight = 1;
    /// <summary>
    /// 输出燥点的浓度
    /// </summary>
    public int ChaosWight
    {
        get { return chaosWight; }
        set { chaosWight = value; }
    }

Color backgroundColor = Color.White;
    /// <summary>
    /// 自定义背景色(默认白色)
    /// </summary>
    public Color BackgroundColor
    {
        get { return backgroundColor; }
        set { backgroundColor = value; }
    }

Color[] colors = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple };
    /// <summary>
    /// 自定义随机颜色数组
    /// </summary>
    public Color[] Colors
    {
        get { return colors; }
        set { colors = value; }
    }

string[] fonts = { "Arial", "Georgia" };
    /// <summary>
    /// 自定义字体数组
    /// </summary>
    public string[] Fonts
    {
        get { return fonts; }
        set { fonts = value; }
    }

#region 产生波形滤镜效果

private const double PI = 3.1415926535897932384626433832795;
    private const double PI2 = 6.283185307179586476925286766559;

/// <summary>
    /// 正弦曲线Wave扭曲图片(Edit By 51aspx.com)
    /// </summary>
    /// <param>图片路径</param>
    /// <param>如果扭曲则选择为True</param>
    /// <param>波形的幅度倍数,越大扭曲的程度越高,一般为3</param>
    /// <param>波形的起始相位,取值区间[0-2*PI)</param>
    /// <returns></returns>
    public System.Drawing.Bitmap TwistImage(Bitmap srcBmp, bool bXDir, double dMultValue, double dPhase)
    {
        System.Drawing.Bitmap destBmp = new Bitmap(srcBmp.Width, srcBmp.Height);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgywf.html