我真的需要java程序的帮助......我在运行程序时遇到错误。 我的目标是将两个图像组合成一个三维图像。将使用红色/蓝色眼镜观看这些图像以提供3D效果。最终图像将尝试成为原始原始图像中对象的灰度。在尝试创建3D图像之前,我必须验证两个图像是否具有相同的宽度和高度。如果图像不匹配,请打印出错误消息并退出程序。
错误:无法解析宽度
height cannot be resolved
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);
// …
}
}
}
}
我被困在这里,我需要帮助..
答案 0 :(得分:0)
p3 = new Picture (width, height);
未声明width
或height
。您需要声明它们并设置为适当的值。正如您在modifyPicture
函数中所做的那样。
确保p1
,p2
和p3
具有相同的尺寸,否则modifyPicture
将无法正常工作。