private void connected( int imageWidth, int imageHeight, int x, int y, byte L)//data为图像数据,L为标记序号
{ data[y * imageWidth + x] = L; if ((x < (imageWidth - 1)) && (x >= 0))
{
if (data[y * imageWidth + x + 1] == 1)
{
connected(imageWidth, imageHeight, x + 1, y, L);
}
}
if ((x < imageWidth ) && (x > 0))
{
if (data[y * imageWidth + x - 1] == 1)//
{
connected(imageWidth, imageHeight, x - 1, y, L);
}
}//*/
if ((y < (imageHeight - 1))&&(y >= 0))
{
if (data[(y + 1) * imageWidth + x] == 1)//
{
connected( imageWidth, imageHeight, x, y + 1, L);
}
}
if ((y < imageHeight ) && (y > 0))
{
if (data[(y - 1) * imageWidth + x] == 1)//
{
connected( imageWidth, imageHeight, x, y - 1, L);
}
}//*/ } //对连通域标记
private void area( int imageWidth, int imageHeight)
{
byte L = 2;
//每个连通域进行标号,标号为1,2,3,......
for (int i = 0; i < imageHeight; i++)
{
for (int j = 0; j < imageWidth; j++)
{
if (data[i * imageWidth + j] == 1)
{
connected( imageWidth, imageHeight, j, i, L);
L += 1;
}
}
}
}为什么对某些图片进行处理的时候会出错,错误为未处理的“System.StackOverflowException”类型的异常,且当前堆栈处于溢出状态,无法计算表达式的值
{ data[y * imageWidth + x] = L; if ((x < (imageWidth - 1)) && (x >= 0))
{
if (data[y * imageWidth + x + 1] == 1)
{
connected(imageWidth, imageHeight, x + 1, y, L);
}
}
if ((x < imageWidth ) && (x > 0))
{
if (data[y * imageWidth + x - 1] == 1)//
{
connected(imageWidth, imageHeight, x - 1, y, L);
}
}//*/
if ((y < (imageHeight - 1))&&(y >= 0))
{
if (data[(y + 1) * imageWidth + x] == 1)//
{
connected( imageWidth, imageHeight, x, y + 1, L);
}
}
if ((y < imageHeight ) && (y > 0))
{
if (data[(y - 1) * imageWidth + x] == 1)//
{
connected( imageWidth, imageHeight, x, y - 1, L);
}
}//*/ } //对连通域标记
private void area( int imageWidth, int imageHeight)
{
byte L = 2;
//每个连通域进行标号,标号为1,2,3,......
for (int i = 0; i < imageHeight; i++)
{
for (int j = 0; j < imageWidth; j++)
{
if (data[i * imageWidth + j] == 1)
{
connected( imageWidth, imageHeight, j, i, L);
L += 1;
}
}
}
}为什么对某些图片进行处理的时候会出错,错误为未处理的“System.StackOverflowException”类型的异常,且当前堆栈处于溢出状态,无法计算表达式的值
如果调用过深,使用的线程堆栈超过了配额(默认为1兆),系统就会抛出StackOverflowException。