我有点困惑,希望有人能对此事有所了解。我创建了一个从图像数组中删除水平线并返回没有任何水平线的图像数组的函数。但是当我用我的图像数组调用这个函数时,它也会直接修改我传递给它的图像数组。为什么会这样?
例子
int[][] imageArray = ImageToArray();
int[][] _NoLines = RemovedLines(imageArray);
imageArray
应该还有它的台词吧?
如果有人好奇,这是实际功能:
public int[][] RemovedLines(int[][] _baseImage)
{
int width = _baseImage[0].length, height = _baseImage.length;
int white = 0;
int black = 0;
for (int y = 0; y < height; y++) {
white = 0;
black = 0;
for (int x = 0; x < width; x++) {
if(_baseImage[y][x] == 0xFFFFFFFF){
white++;
}else{
black++;
}
}
if(black > white)
{
// line detected fist time
// now get height of line
int _starts = y;
_starts++;
int _end = 0;
for(; _starts < height; _starts++){
white = 0;
black = 0;
for(int _x = 0; _x < width; _x++){
if(_baseImage[_starts][_x] == 0xFFFFFFFF){
white++;
}else{
black++;
}
}
if(white > black){
// end of line height
_end = _starts;
_starts = y;
break;
}
}
white = 0;
black = 0;
for(;_starts < _end; _starts++){
for(int line = 0; line < width; line++){
if(_baseImage[_starts-1][line] != 0xFF000000
&& _baseImage[_starts-2][line] != 0xFF000000
|| _baseImage[_starts+1][line] != 0xFF000000
&& _baseImage[_starts+2][line] != 0xFF000000){
_baseImage[_starts][line] =0xFFFFFFFF;
}
}
}
y = _end;
}
}
return _baseImage;
}