【IT168技术文档】
这样就抓出来图象,并且把每个象素点存放成数组了1 public Stream ReuestImage() 2 { 3 HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create("http://passport.csdn.net/ShowExPwd.aspx?DateTime=2007-1-24"); 4 hwr.ContentType = "application/x-www-form-urlencoded"; 5 hwr.Method = "GET"; 6 HttpWebResponse hw = (HttpWebResponse)hwr.GetResponse(); 7 return hw.GetResponseStream(); 8 } 1 /// <summary> 2 /// 加载图形,象素转换为数组 3 /// </summary> 4 private void Load() 5 { 6 MyNet mn = new MyNet(); 7 bt = (Bitmap)Bitmap.FromStream(mn.ReuestImage()); 8 //bt = (Bitmap)Bitmap.FromFile("c:/tt.bmp"); 9 int x = bt.Width; 10 int y = bt.Height; 11 pixColor = new Color[x , y]; 12 13 for (int i = 0; i < x; i++) 14 { 15 for (int k = 0; k < y; k++) 16 { 17 pixColor[i,k] = bt.GetPixel(i, k); 18 } 19 } 20 }
我想了个简单的办法,用ColorTranslator.ToHtml把pixColor的每个点转换为#000000样式的颜色.去掉#
然后分成3份.
1 for (int i = 0; i < pixColor.GetLength(0); i++) 2 { 3 for (int j = 0; j < pixColor.GetLength(1); j++) 4 { 5 string s = ColorTranslator.ToHtml(pixColor[i, j]).Remove(0,1); 6 string s1 = s.Remove(2); 7 string s2 = s.Remove(0, 2).Remove(2); 8 string s3 = s.Remove(0, 4); 9 10 if (Convert.ToInt32(s1, 16) + Convert.ToInt32(s2, 16) + Convert.ToInt32(s3, 16) < 408) 11 bt.SetPixel(i, j, Color.White); 12 else 13 bt.SetPixel(i,j,Color.Black); 14 } 15 }