Ejemplo n.º 1
0
        public override byte[] CreateImage(out string validataCode)
        {
            Bitmap bitmap;
            string formatString = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";

            GetRandom(formatString, this.ValidataCodeLength, out validataCode);
            MemoryStream       stream  = new MemoryStream();
            AnimatedGifEncoder encoder = new AnimatedGifEncoder();

            encoder.Start();
            encoder.SetDelay(1);
            encoder.SetRepeat(0);
            for (int i = 0; i < 3; i++)
            {
                this.SplitCode(validataCode);
                this.ImageBmp(out bitmap, validataCode);
                bitmap.Save(stream, ImageFormat.Png);
                encoder.AddFrame(Image.FromStream(stream));
                stream = new MemoryStream();
                bitmap.Dispose();
            }
            encoder.OutPut(ref stream);
            bitmap = null;
            stream.Close();
            stream.Dispose();
            return(stream.GetBuffer());
        }
Ejemplo n.º 2
0
        public override byte[] CreateImage(out string validataCode)
        {
            Bitmap bitmap;
            string formatString = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";

            GetRandom(formatString, this.ValidataCodeLength, out validataCode);
            MemoryStream       stream  = new MemoryStream();
            AnimatedGifEncoder encoder = new AnimatedGifEncoder();

            encoder.Start();
            encoder.SetDelay(1);
            encoder.SetRepeat(0);
            Random random = new Random();

            for (int i = 0; i < validataCode.Length; i++)
            {
                this.colors.Add(this.DrawColors[random.Next(this.DrawColors.Length)]);
            }
            for (int j = 0; j < 3; j++)
            {
                string[] strArray = this.SplitCode(validataCode);
                for (int k = 0; k < 2; k++)
                {
                    if (k == 0)
                    {
                        this.ImageBmp(out bitmap, strArray[0]);
                    }
                    else
                    {
                        this.ImageBmp(out bitmap, strArray[1]);
                    }
                    bitmap.Save(stream, ImageFormat.Png);
                    encoder.AddFrame(Image.FromStream(stream));
                    stream = new MemoryStream();
                    bitmap.Dispose();
                }
            }
            encoder.OutPut(ref stream);
            bitmap = null;
            stream.Close();
            stream.Dispose();
            return(stream.GetBuffer());
        }