Note that there are some explanatory texts on larger screens.

plurals
  1. POcreating a 3d image in java help please
    text
    copied!<p>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. </p> <p>error: width cannot be resolved</p> <pre><code> height cannot be resolved </code></pre> <h2>i wrote the program as below...</h2> <pre><code>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 &lt; width ; ++xPos) { for (int yPos = 0 ; yPos &lt; 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); // … } } } } </code></pre> <p>I am stuck here and i need help..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload