예제 #1
0
        //下载图像并分割
        private void btnDown_Click(object sender, EventArgs e)
        {
            Http.Http http = new Http.Http();
            picSource.Image = http.PostImg(txtUrlImg.Text.Trim());

            img = new Bitmap(picSource.Image);  //加载图像

            if (img != null)
            {
                YanMoCaptche yanmo = new YanMoCaptche();

                //去除红色
                img = yanmo.ClearRedColor(img, 130);

                //去除绿色
                img = yanmo.ClearGreenColor(img, 150);

                //去除蓝色
                img = yanmo.ClearBlueColor(img, 200);

                //灰度化
                img = yanmo.GrayImage(img, 200);

                //去噪
                img = yanmo.ClearNoise(img);
                picSource.Image = img;

                return;

                bit = yanmo.InciseImage(img);  //切割

                for (int i = 0; i < captche.Length; i++)    //填充
                {
                    string code = string.Format("{0}", yanmo.CharacterLine(bit[i], false, 4));
                    captche[i].Character = code;
                    //captche[i].Character = yanmo.CountBlack(bit[i],0).ToString();
                    captche[i].Bearing = "H";
                    captche[i].Line = "6";
                }

                pic1.Image = bit[0];
                pic2.Image = bit[1];
                pic3.Image = bit[2];
                pic4.Image = bit[3];
            }
            rtxState.Clear();
        }
예제 #2
0
        private void btnCaptche_Click(object sender, EventArgs e)
        {
            if (bit != null)
            {
                //灰度
                //picCaptche.Image = SetImageHeiSe(bit);

                //去点
                //picCaptche.Image = ClearPixel(SetImageHeiSe(bit));  //灰度操作:SetImageHeiSe(bit)

                //打印
                //PrintPixel(bit);

                //分割
                //Bitmap[] b = PixelN(4, bit);
                //for (int i = 0; i < b.Length; i++)
                //{
                //    b[i].Save("H" + i.ToString() + ".bmp");
                //    rtxCaptche.AppendText(CountBlack(b[i], 0).ToString() + " " + CountBlack(b[i], 255).ToString() + "\r\n");
                //    rtxCaptche.AppendText(CharacterLine(b[i], true, 4) + "\r\n");
                //    rtxCaptche.AppendText(CharacterLine(b[i], true, 9) + "\r\n\r\n");
                //    rtxCaptche.AppendText(CharacterLine(b[i], false, 5) + "\r\n");
                //    rtxCaptche.AppendText(CharacterLine(b[i], false, 10) + "\r\n");
                //}

                YanMoCaptche yanmo = new YanMoCaptche();
                bit = yanmo.GrayImage(bit);
                bit = yanmo.ClearNoise(bit);
                Bitmap[] b = yanmo.InciseImage(bit);
                for (int i = 0; i < b.Length; i++)
                {
                    b[i].Save("R" + i.ToString() + ".bmp");
                    rtxCaptche.AppendText((i+1).ToString() +":" + yanmo.CharacterLine(b[i], true, 5) + "\r\n");
                }
                rtxCaptche.AppendText("\r\n");
            }
            else
            {
                MessageBox.Show("对你无语了!", "出错");
            }
        }
예제 #3
0
 //H4填充
 private void button2_Click(object sender, EventArgs e)
 {
     YanMoCaptche yanmo = new YanMoCaptche();
     for (int i = 0; i < captche.Length; i++)
     {
         string code = string.Format("{0}{1}{2}{3}{4}",
             yanmo.CharacterLine(bit[i], true, 3),
             yanmo.CharacterLine(bit[i], true, 5),
             yanmo.CharacterLine(bit[i], true, 8),
             yanmo.CharacterLine(bit[i], true, 11),
             yanmo.CharacterLine(bit[i], true, 13));
         captche[i].Character = code;
         captche[i].Bearing = "H";
         captche[i].Line = "6";
     }
 }
예제 #4
0
 //H7填充
 private void button4_Click(object sender, EventArgs e)
 {
     YanMoCaptche yanmo = new YanMoCaptche();
     for (int i = 0; i < captche.Length; i++)
     {
         captche[i].Character = yanmo.CharacterLine(bit[i], true, 7);
         captche[i].Bearing = "H";
         captche[i].Line = "7";
     }
 }
예제 #5
0
        //选择图像
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Reset();
            open.RestoreDirectory = true;
            open.ShowDialog();
            txtUrlImg.Text = open.FileName;
            if (txtUrlImg.Text.Trim() != string.Empty)
            {
                try
                {
                    picSource.Image = Image.FromFile(txtUrlImg.Text);
                    img = new Bitmap(picSource.Image);
                    if (img != null)
                    {
                        YanMoCaptche yanmo = new YanMoCaptche();
                        img = yanmo.GrayImage(img, 180);     //灰度化
                        img = yanmo.ClearNoise(img);    //去噪
                        bit = yanmo.InciseImage(img);  //切割

                        for (int i = 0; i < bit.Length; i++)    //冲洗
                        {
                            //bit[i].Save("S" + i.ToString() + ".bmp");
                            bit[i] = yanmo.RinseImage(bit[i]);
                            //bit[i].Save("H" + i.ToString() + ".bmp");
                        }

                        pic1.Image = bit[0];
                        pic2.Image = bit[1];
                        pic3.Image = bit[2];
                        pic4.Image = bit[3];
                    }
                    rtxState.Clear();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "郁闷!你选的是图片吗?");
                }
            }
        }