Beispiel #1
0
        private void DoFloat(UInt32 NumberOfPoints, BinaryReader _br, Pen p)
        {
            System.DrawingCore.PointF[] Points = new System.DrawingCore.PointF[NumberOfPoints];
            bool first = true;

            for (int i = 0; i < NumberOfPoints; i++)
            {
                Points[i].X = _br.ReadSingle();
                Points[i].Y = _br.ReadSingle();
            }
            PointF PointA = new PointF();
            PointF PointB = new PointF();

            for (int i = 0; i < NumberOfPoints; i++)
            {
                if (first)
                {
                    PointA = Points[i];
                    first  = false;
                }
                else
                {
                    PointB = Points[i];
                    DoInstructions(PointA.X, PointB.X, PointA.Y, PointB.Y, p);
                    PointA = PointB;
                }
            }
        }
Beispiel #2
0
 private void DoCompressed(UInt32 NumberOfSegments, BinaryReader _br, Pen p, UInt32 Offset, UInt32 NumberOfPoints, float Tension)
 {
     //bool first = true;
     PointF[] Points = new System.DrawingCore.PointF[NumberOfPoints];
     for (int i = 0; i < NumberOfPoints; i++)
     {
         Points[i].X = (float)_br.ReadInt16();
         Points[i].Y = (float)_br.ReadInt16();
     }
     DoInstructions(Points, p, Offset, NumberOfSegments, Tension);
 }
Beispiel #3
0
        /// <summary>
        /// 验证码图片 => byte[]
        /// </summary>
        /// <param name="verifyCode">验证码</param>
        /// <param name="width">宽</param>
        /// <param name="height">高</param>
        /// <returns>byte[]</returns>
        public byte[] CreateByteByImgCheckCode(string checkCode, int width, int height)
        {
            Font     font = new Font("Arial", 14, (FontStyle.Bold | FontStyle.Italic));
            Brush    brush;
            Bitmap   bitmap     = new Bitmap(width, height);
            Graphics g          = Graphics.FromImage(bitmap);
            SizeF    totalSizeF = g.MeasureString(checkCode, font);
            SizeF    curCharSizeF;
            PointF   startPointF = new PointF(0, (height - totalSizeF.Height) / 2);
            Random   random      = new Random(); //随机数产生器

            g.Clear(Color.White);                //清空图片背景色
            for (int i = 0; i < checkCode.Length; i++)
            {
                brush = new LinearGradientBrush(new Point(0, 0), new Point(1, 1), Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)), Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)));
                g.DrawString(checkCode[i].ToString(), font, brush, startPointF);
                curCharSizeF   = g.MeasureString(checkCode[i].ToString(), font);
                startPointF.X += curCharSizeF.Width;
            }

            //画图片的干扰线
            for (int i = 0; i < 10; i++)
            {
                int x1 = random.Next(bitmap.Width);
                int x2 = random.Next(bitmap.Width);
                int y1 = random.Next(bitmap.Height);
                int y2 = random.Next(bitmap.Height);
                g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
            }

            //画图片的前景干扰点
            for (int i = 0; i < 100; i++)
            {
                int x = random.Next(bitmap.Width);
                int y = random.Next(bitmap.Height);
                bitmap.SetPixel(x, y, Color.FromArgb(random.Next()));
            }

            g.DrawRectangle(new Pen(Color.Silver), 0, 0, bitmap.Width - 1, bitmap.Height - 1); //画图片的边框线
            g.Dispose();

            //保存图片数据
            MemoryStream stream = new MemoryStream();

            bitmap.Save(stream, ImageFormat.Jpeg);
            //输出图片流
            return(stream.ToArray());
        }