c#实现识别图片上的验证码数字

2019-12-30 11:03:40刘景俊
  • posx1 = posx1 - leftSpan;  if (posx2 + Span - leftSpan < bmpobj.Width) 
  • posx2 = posx2 + Span - leftSpan;  } 
  • //复制新图  Rectangle cloneRect = new Rectangle(posx1, posy1, posx2 - posx1 + 1, posy2 - posy1 + 1); 
  • bmpobj = bmpobj.Clone(cloneRect, bmpobj.PixelFormat);  } 
  •   /// <summary> 
  • /// 得到有效图形,图形为类变量  /// </summary> 
  • /// <param name="dgGrayValue">灰度背景分界值</param>  /// <param name="CharsCount">有效字符数</param> 
  • /// <returns></returns>  public void GetPicValidByValue(int dgGrayValue) 
  • {  int posx1 = bmpobj.Width; int posy1 = bmpobj.Height; 
  • int posx2 = 0; int posy2 = 0;  for (int i = 0; i < bmpobj.Height; i++) //找有效区 
  • {  for (int j = 0; j < bmpobj.Width; j++) 
  • {  int pixelValue = bmpobj.GetPixel(j, i).R; 
  • if (pixelValue < dgGrayValue) //根据灰度值  { 
  • if (posx1 > j) posx1 = j;  if (posy1 > i) posy1 = i; 
  •   if (posx2 < j) posx2 = j; 
  • if (posy2 < i) posy2 = i;  }; 
  • };  }; 
  • //复制新图  Rectangle cloneRect = new Rectangle(posx1, posy1, posx2 - posx1 + 1, posy2 - posy1 + 1); 
  • bmpobj = bmpobj.Clone(cloneRect, bmpobj.PixelFormat);  } 
  •   /// <summary> 
  • /// 得到有效图形,图形由外面传入  /// </summary> 
  • /// <param name="dgGrayValue">灰度背景分界值</param>  /// <param name="CharsCount">有效字符数</param> 
  • /// <returns></returns>  public Bitmap GetPicValidByValue(Bitmap singlepic, int dgGrayValue)