예제 #1
0
            public static string[] StringSplit(string strSource, string strSplit)
            {
                string[] textArray1 = new string[1];
                int      num1       = strSource.IndexOf(strSplit, 0);

                if (num1 < 0)
                {
                    textArray1[0] = strSource;
                    return(textArray1);
                }
                textArray1[0] = strSource.Substring(0, num1);
                return(StrDeal.StringSplit(strSource.Substring(num1 + strSplit.Length), strSplit, textArray1));
            }
예제 #2
0
            public static string[] StringSplit(string strSource, string strSplit, string[] attachArray)
            {
                string[] textArray1 = new string[attachArray.Length + 1];
                attachArray.CopyTo(textArray1, 0);
                int num1 = strSource.IndexOf(strSplit, 0);

                if (num1 < 0)
                {
                    textArray1[attachArray.Length] = strSource;
                    return(textArray1);
                }
                textArray1[attachArray.Length] = strSource.Substring(0, num1);
                return(StrDeal.StringSplit(strSource.Substring(num1 + strSplit.Length), strSplit, textArray1));
            }
예제 #3
0
        public byte[] CreatePicCode(string VNum)
        {
            int gWidth  = (int)(VNum.Length * 17);// Gwidth为图片宽度,根据字符长度自动更改图片宽度
            int gHeight = 20;

            System.Drawing.Bitmap Img = new System.Drawing.Bitmap(gWidth, gHeight);

            Graphics     g;
            MemoryStream ms = new MemoryStream();

            string tmpstr = "";

            for (int mm = 0; mm < VNum.Length; mm++)
            {
                tmpstr += VNum[mm] + " ";
            }
            VNum = tmpstr;


            g = Graphics.FromImage(Img);

            SolidBrush drawBrushNew = new SolidBrush(Color.White);

            g.FillRectangle(drawBrushNew, 0, 0, Img.Width, Img.Height);

            // Create font and brush.

            FontStyle style = FontStyle.Bold;
            //style |= FontStyle.Bold;
            Font drawFont = new Font("Arial", 12, style);

            SolidBrush drawBrush = new SolidBrush(Color.Red);


            Color  clr        = Color.Red;
            Pen    p          = new Pen(clr, StrDeal.LoginRandNum(1, 4));
            int    x1         = StrDeal.LoginRandNum(1, gWidth);
            int    y1         = StrDeal.LoginRandNum(1, gHeight);
            int    x2         = x1 + StrDeal.LoginRandNum(15, gWidth - 15);
            int    y2         = y1 + StrDeal.LoginRandNum(0, gHeight);
            PointF drawPoint1 = new PointF(x1, y1);
            PointF drawPoint2 = new PointF(x2, y2);

            for (int i = 0; i < Convert.ToInt32(StrDeal.LoginRandNum(300, 415)); i++)
            {
                // 生成一个随机宽度
                clr     = Color.FromArgb(StrDeal.LoginRandNum(100, 255), StrDeal.LoginRandNum(51, 255), StrDeal.LoginRandNum(11, 255));
                p.Color = clr;
                p.Width = StrDeal.LoginRandNum(1, 4);

                x1           = StrDeal.LoginRandNum(1, gWidth);
                y1           = StrDeal.LoginRandNum(1, gHeight);
                x2           = x1 + StrDeal.LoginRandNum(15, gWidth - 15);
                y2           = y1 + StrDeal.LoginRandNum(0, gHeight);
                drawPoint1.X = x1;
                drawPoint1.Y = y1;
                drawPoint2.X = x2;
                drawPoint2.Y = y2;
                g.DrawLine(p, drawPoint1, drawPoint2);
            }
            p.Dispose();
            PointF drawPoint = new PointF(3, 3);

            g.DrawString(VNum, drawFont, drawBrush, drawPoint); //在矩形内绘制字串(字串,字体,画笔颜色,左上x.左上y)

            Img.Save(ms, ImageFormat.Jpeg);

            return(ms.ToArray());
        }