日期:2014-05-17 浏览次数:20876 次
private void AutoGrayValue(ref Point left,ref Point right,ref int dgGrayValue,int CharsCount,bool auto) { for (int i = 0; i < mBitmap.Height; i++) //找有效区,可能是平行四边形 { for (int j = 0; j < mBitmap.Width; j++) { int pixelValue = GetGrayNumColor(mBitmap.GetPixel(j, i));//获取指定位置的灰度值 if (pixelValue < dgGrayValue) //根据阈值划分 { if (right.X < j) right.X = j; if (right.Y < i) right.Y = i; if (left.X > j) left.X = j; if (left.Y > i) left.Y = i; }; }; }; if (left.X > right.X || left.Y > right.Y) { MessageBox.Show(""); } if (auto) { if (right.X - left.X >= mBitmap.Width - 1)//阈值不准确 无法区分 自动递归调整 { if (dgGrayValue ==0) { dgGrayValue = 255; } dgGrayValue--; left.X = mBitmap.Width - 1; left.Y = mBitmap.Height - 1; right.X = 0; right.Y = 0; AutoGrayValue(ref left,ref right,ref dgGrayValue, CharsCount, auto); } } }