Reputation: 119
I'm working on a project that will do a simple contrast of an image, I have already scanned through the arrays to find the min and max values but now I have to paint the image.
I keep getting this error "The operator * is undefined for the argument type(s) drawingpanel, double"
here is the code
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);
}
}
Any help would be appreciated.. thanks!
also this is where i compute my min maxes...
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];
}
}
}
}
and some other variables in my 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();
}
}
Upvotes: 0
Views: 821
Reputation: 3020
The error msg tells you can not use the operator '*' between maxshade
and ((double)(DrawingPanel.imageArray[r][c] - minshade) / (maxedshade - minshade))
. Because maxshade is type of DrawingPanel
, NOT a numeric(double/long/float/int...).
As I look into your 2nd code block,I see a static variable name maxedshade
.It seems like a numeric.
And then I look into your error line:
newc = Math.round(maxshade * ((double)(DrawingPanel.imageArray[r][c] - minshade) / (maxedshade - minshade))); //error here!!!
Did you made a input mistake on "maxshade" ? Should it be maxedshade ?
Upvotes: 1