我正在开发一个能够对图像进行简单对比的项目,我已经扫描了数组以找到最小值和最大值,但现在我必须绘制图像。
我不断收到此错误“对于参数类型绘图面板,运算符*未定义,双倍”
这是代码
public void simple (Graphics g) {
if (DrawingPanel.imageArray != null) {
int width = getWidth();
int height = getHeight();
int hPos = (width - DrawingPanel.imageArray[0].length) / 2;
int vPos = (height - DrawingPanel.imageArray.length) / 2;
for (int r = 0; r < DrawingPanel.imageArray.length; r++)
for (int c = 0; c < DrawingPanel.imageArray[r].length; c++) {
newc = Math.round(maxshade * ((double)(DrawingPanel.imageArray[r][c] - minshade) / (maxedshade - minshade))); //error here!!!
g.setColor(new Color(DrawingPanel.imageArray[r][c], DrawingPanel.imageArray[r][c], DrawingPanel.imageArray[r][c]));
g.drawLine(c+hPos, r+vPos, c+hPos, r+vPos);
}
g.setColor(Color.black);
g.drawRect(hPos, vPos, DrawingPanel.imageArray[0].length, DrawingPanel.imageArray.length);
}
}
任何帮助将不胜感激..谢谢!
这也是我计算我的最大值的地方......
public static void computeImageStatistics(DrawingPanel array) {
DrawingPanel.array = carray;
maxedshade = carray[0][0];
for (int i = 0; i < carray.length; i++) {
for (int j = 0; j < carray[i].length; j++) {
if (carray[i][j] > maxedshade) {
maxedshade = carray[i][j];
}
}
}
minshade = carray[0][0];
for (int i = 0; i < carray.length; i++) {
for (int j = 0; j < carray[i].length; j++) {
if (minshade > carray[i][j]) {
minshade = carray[i][j];
}
}
}
}
以及我的DrawingPanel中的一些其他变量..
public void showImage(File fileName) {
Scanner scan;
try {
scan = new Scanner(fileName);
typefile = scan.next();
iname = scan.next();
width = scan.nextInt();
height = scan.nextInt();
maxshade = scan.nextInt();
array = new int[width][height];
for(int r = 0; r < array.length; r++)
for(int c = 0; c < array[r].length; c++)
array[r][c] = scan.nextInt();
imageArray = array;
repaint();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
错误消息告诉您不能在maxshade
和((double)(DrawingPanel.imageArray[r][c] - minshade) / (maxedshade - minshade))
之间使用运算符'*'。因为maxshade是DrawingPanel
的类型,而不是数字(double / long / float / int ...)。
当我查看你的第二个代码块时,我看到一个静态变量名maxedshade
。它看起来像一个数字。
然后我调查你的错误行:
newc = Math.round(maxshade * ((double)(DrawingPanel.imageArray[r][c] - minshade) / (maxedshade - minshade))); //error here!!!
您是否在“ maxshade ”上输入错误?它应该是 maxedshade 吗?