0

我正在做一个对图像进行简单对比的项目,我已经扫描了数组以找到最小值和最大值,但现在我必须绘制图像。

我不断收到此错误“操作符 * 未定义参数类型绘图面板,双精度”

这是代码

    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];
                }
    }
            }
    }

和我的绘图面板中的一些其他变量..

     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();
        }

 }
4

1 回答 1

1

错误消息告诉您不能在maxshadeand之间使用运算符 '*' ((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吗?

于 2012-09-20T02:31:23.497 回答