I really need help with the java program…i am getting errors when i am running the programs.
My goal for this lab is to combine two images into a single 3 dimension image. These images will be viewed using red/blue glasses to give the 3D effect. The final image will attempt to be a grayscale of the object in the original original images. I have to verify that the two images have the same width and height before attempting to create the 3D image. If the images do not match, print out an error message and exit the program.
error: width cannot be resolved
height cannot be resolved
i wrote the program as below…
public class 3dImage {
public static void main(String[] args) {
// Access and open the picture
String filename = FileChooser.pickAFile ();
Picture p1 = new Picture (filename);
//second picture
String filename2 = FileChooser.pickAFile ();
Picture p2 = new Picture (filename);
//get the width and height from p1 and p2
Picture p3;
p3 = new Picture (width, height);
// call the method to modify the Pictture
modifyPicture (p1, p2, p3);
// explore (display) the picture
p3.explore();
} // end of main
public static void modifyPicture (Picture p1, Picture p2, Picture p3) {
// get the width and height of the picture
int width = p1.getWidth();
int height = p1.getHeight();
//shows width and height
System.out.println ("Width: " + width + ", Height: " + height);
// loop over the pixels
for (int xPos = 0 ; xPos < width ; ++xPos) {
for (int yPos = 0 ; yPos < height ; ++yPos) {
// access the pixel to be modifed
Pixel pix1 = p1.getPixel (xPos, yPos);
Pixel pix2 = p2.getPixel (xPos, yPos);
Pixel pix3 = p3.getPixel (xPos, yPos);
// modify the pixel
int redAmount = pix1.getRed (255);
int greenAmount = pix1.getGreen (0);
int blueAmount = pix1.getBlue (0);
int grayAmount1 = (int)(redAmount * 0.299 + greenAmount * 0.587 + blueAmount * 0.114);
redAmount = pix2.getRed(0);
greenAmount = pix2.getGreen(255);
blueAmount = pix2.getBlue(255);
int grayAmount2 = (int)(redAmount * 0.299 + greenAmount * 0.587 + blueAmount * 0.114);
pix3.setRed (grayAmount1);
pix3.setGreen (grayAmount2);
pix3.setBlue (grayAmount2);
// …
}
}
}
}
I am stuck here and i need help..
Neither
widthnorheighthas been declared. You need to declare them and set to appropriate values. As you did inmodifyPicturefunction.Make sure
p1,p2andp3have the same size, otherwisemodifyPicturewon’t work correctly.