我正在做一个将对图像进行简单对比的项目,我已经扫描了数组以找到最小值和最大值,但是现在我必须绘制图像。
我不断收到此错误“参数类型为drawingpanel的运算符*未定义, double ”
这是代码
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();
}
}
最佳答案
错误消息msg告诉您不能在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 吗?