private void button2_Click(object sender, EventArgs e) { if (textBox2.Text.Length < 5) { MessageBox.Show("输入无效...长度错误..."); return; } for (int x = 0; x < 5; x++) { if (x == 0 && textBox2.Text.Substring(0, 1)!=" ") { string s = WAPcode.ConvertToStr(pictureBox2.Image as Bitmap) + " " + textBox2.Text.Substring(0, 1) + "\r\n"; FileStream fs = new FileStream("code.txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs, Encoding.Default); sw.Write(s); sw.Close(); fs.Close(); } if (x == 1 && textBox2.Text.Substring(1, 1) != " ") { string s = WAPcode.ConvertToStr(pictureBox3.Image as Bitmap) + " " + textBox2.Text.Substring(1, 1) + "\r\n"; FileStream fs = new FileStream("code.txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs, Encoding.Default); sw.Write(s); sw.Close(); fs.Close(); } if (x == 2 && textBox2.Text.Substring(2, 1) != " ") { string s = WAPcode.ConvertToStr(pictureBox4.Image as Bitmap) + " " + textBox2.Text.Substring(2, 1) + "\r\n"; FileStream fs = new FileStream("code.txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs, Encoding.Default); sw.Write(s); sw.Close(); fs.Close(); } if (x == 3 && textBox2.Text.Substring(3, 1) != " ") { string s = WAPcode.ConvertToStr(pictureBox5.Image as Bitmap) + " " + textBox2.Text.Substring(3, 1) + "\r\n"; FileStream fs = new FileStream("code.txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs, Encoding.Default); sw.Write(s); sw.Close(); fs.Close(); } if (x == 4 && textBox2.Text.Substring(4, 1) != " ") { string s = WAPcode.ConvertToStr(pictureBox6.Image as Bitmap) + " " + textBox2.Text.Substring(4, 1) + "\r\n"; FileStream fs = new FileStream("code.txt", FileMode.Append); StreamWriter sw = new StreamWriter(fs, Encoding.Default); sw.Write(s); sw.Close(); fs.Close(); } } textBox2.Text = ""; label1.Text = DateTime.Now.ToString() + " 提交成功..."; }
private void pictureBox6_Click(object sender, EventArgs e) { MessageBox.Show(WAPcode.GetChar(pictureBox6.Image as Bitmap)); }
private void button1_Click(object sender, EventArgs e) { string url = "http://weibo.cn/interface/f/ttt/captcha/show.php?r="+DateTime.Now.ToString("mmss"); string filepath = DateTime.Now.ToString("mmss") + "pic.gif"; WebClient mywebclient = new WebClient(); mywebclient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36"); mywebclient.DownloadFile(url, filepath); Bitmap Picbit = new Bitmap(Bitmap.FromFile(filepath)); Bitmap bm =WAPcode.Binaryzation(WAPcode.CleanPic(Picbit)); pictureBox1.Image = Image.FromHbitmap(bm.GetHbitmap()); int[,] position = WAPcode.DividePic(bm); try { Bitmap newImg = new Bitmap(position[0, 1] - position[0, 0], position[0, 3] - position[0, 2]); Graphics g = Graphics.FromImage(newImg); g.DrawImage(bm, 0, 0, new Rectangle(position[0, 0], position[0, 2], position[0, 1] - position[0, 0], position[0, 3] - position[0, 2]), GraphicsUnit.Pixel); pictureBox2.Image = Image.FromHbitmap(newImg.GetHbitmap()); Bitmap newImg2 = new Bitmap(position[1, 1] - position[1, 0], position[1, 3] - position[1, 2]); Graphics g2 = Graphics.FromImage(newImg2); g2.DrawImage(bm, 0, 0, new Rectangle(position[1, 0], position[1, 2], position[1, 1] - position[1, 0], position[1, 3] - position[1, 2]), GraphicsUnit.Pixel); pictureBox3.Image = Image.FromHbitmap(newImg2.GetHbitmap()); Bitmap newImg3 = new Bitmap(position[2, 1] - position[2, 0], position[2, 3] - position[2, 2]); Graphics g3 = Graphics.FromImage(newImg3); g3.DrawImage(bm, 0, 0, new Rectangle(position[2, 0], position[2, 2], position[2, 1] - position[2, 0], position[2, 3] - position[2, 2]), GraphicsUnit.Pixel); pictureBox4.Image = Image.FromHbitmap(newImg3.GetHbitmap()); Bitmap newImg4 = new Bitmap(position[3, 1] - position[3, 0], position[3, 3] - position[3, 2]); Graphics g4 = Graphics.FromImage(newImg4); g4.DrawImage(bm, 0, 0, new Rectangle(position[3, 0], position[3, 2], position[3, 1] - position[3, 0], position[3, 3] - position[3, 2]), GraphicsUnit.Pixel); pictureBox5.Image = Image.FromHbitmap(newImg4.GetHbitmap()); Bitmap newImg5 = new Bitmap(position[4, 1] - position[4, 0], position[4, 3] - position[4, 2]); Graphics g5 = Graphics.FromImage(newImg5); g5.DrawImage(bm, 0, 0, new Rectangle(position[4, 0], position[4, 2], position[4, 1] - position[4, 0], position[4, 3] - position[4, 2]), GraphicsUnit.Pixel); pictureBox6.Image = Image.FromHbitmap(newImg5.GetHbitmap()); } catch { MessageBox.Show("分离失败..."); } //Console.WriteLine(WAPcode.Similarity(newImg, newImg)); //Bitmap bm = WAPcode.CleanPic(new Bitmap(Bitmap.FromFile(textBox1.Text))); //Bitmap bm = ConvertTo1Bpp1(new Bitmap(Bitmap.FromFile(textBox1.Text))); //FileStream fs = new FileStream("code.txt", FileMode.Create); //StreamWriter sw = new StreamWriter(fs, Encoding.Default); //for (int i = 0; i < bm.Height; i++) //{ // for (int j = 0; j < bm.Width; j++) // { // //获取该点的像素的RGB的颜色 // Color color = bm.GetPixel(j, i); // if (color.R == 0) // sw.Write("1"); // else // sw.Write(" "); // } // sw.Write("\r\n"); //} //sw.Close(); //fs.Close(); //int[] arrayx=new int[999]; //int[] arrayy = new int[999]; //int p = 0; //for (int i = 1; i < bm.Height-1; i++) //{ // for (int j = 1; j < bm.Width-1; j++) // { // if(bm.GetPixel(j,i).R == 0) // if (SearchNeighbor(j, i, bm) > 3) // { // bm.SetPixel(j, i, Color.FromArgb(255, 255, 255)); // arrayx[p] = i; // arrayy[p] = j; // p++; // } // } //} //for (p=p-1; p > 0; p--) //{ // bm.SetPixel(arrayy[p], arrayx[p] + 1, Color.FromArgb(255, 255, 255)); // //bm.SetPixel(arrayy[p]-1, arrayx[p] + 1, Color.FromArgb(0, 255, 255)); // //bm.SetPixel(arrayy[p]+1, arrayx[p] + 1, Color.FromArgb(0, 255, 255)); // //bm.SetPixel(arrayy[p]+1, arrayx[p] - 1, Color.FromArgb(0, 255, 255)); // //bm.SetPixel(arrayy[p]-1, arrayx[p] - 1, Color.FromArgb(0, 255, 255)); // //bm.SetPixel(arrayy[p], arrayx[p] - 1, Color.FromArgb(0, 255, 255)); // //bm.SetPixel(arrayy[p] + 1, arrayx[p] , Color.FromArgb(0, 255, 255)); // //bm.SetPixel(arrayy[p] - 1, arrayx[p] , Color.FromArgb(0, 255, 255)); //} //bm = hough_line(bm,40); }