我已经定义了数组gx,数组arr是short类型。但为什么左边的操作可能以int类型结束,我必须简化它?编译器错误是可能的有损转换从int到短。从int到short的可能有损转换
这是我的代码。
public PixImage sobelEdges() {
short gy=0;
for(int x=1;x<width-1;x++){
for(int y=1;y<height-1;y++){
// if(x=){
for(int z=0;z<3;z++){
gx[x][y][z]=arr[x-1][y-1][z]-arr[x+1][y-1][z]+2*arr[x-1][y][z]-2*arr[x+1][y][z]+arr[x-1][y+1][z]-arr[x+1][y+1][z];
}
// }
}
}
return this;
// Don't forget to use the method mag2gray() above to convert energies to
// pixel intensities.
}
是不是因为所谓的拆箱?这意味着每次我进行手术时都需要施放?
'int'大于'short'。可能会丢失位。 –
编译器可能注意到您将“short”值相乘并将结果存储为“short”。乘法的结果有可能比“short”更大。这与拳击/取消装箱无关。例如,这指的是从'int'到'Integer'的隐式转换。 – bstar55
试着将你的2做短裤。 (短)2 * arr ... – bstar55