我需要比较两个相似图像中的像素,创建一个保存的第三个图像,其中两个图像之间相同的像素变为蓝色。代码还需要在开始比较之前检查图像是否具有相同的大小,如果它们的大小不同,则会向控制台退出并出错。 这是我的代码。我仍然需要覆盖两个图像并将相似的像素转为蓝色。 我需要使用Filechooser.pickAFile,但除此之外,我完全迷失了如何去做。
// Karl Thomas
// kthoma34
// Mon @ 4:00
import java.awt.Color;
public class PP2kthoma34
{
public static void main (String[] args)
{
// Original picture
Picture p1; // create the variable
String fileName = FileChooser.pickAFile();
FileChooser.setMediaPath ( fileName );
System.out.println (fileName);
p1 = new Picture( fileName );
// Width and length of original picture
int width1 = p1.getWidth();
int height1 = p1.getHeight();
Pixel[] pixelArray1 = p1.getPixels();
System.out.println(pixelArray1.length + "pixels");
System.out.println("");
// Modified picture
Picture p2; // create the variable
String filename2;
filename2 = FileChooser.pickAFile();
FileChooser.setMediaPath ( filename2 );
System.out.println (filename2);
p2 = new Picture( filename2 );
//Width and Height of manipulated picture
int width2 = p2.getWidth();
int height2 = p2.getHeight();
Pixel[] pixelArray2 = p2.getPixels();
System.out.println(pixelArray2.length + "pixels");
System.out.println("");
//checking that the images are the same size
if ((width1 != width2) || (height1 != height2))
{
System.err.println("Error: Image dimensions do not match");
System.exit(1);
}
// Save Third image with similarities highlighted in blue.
String filename3;
filename3 = FileChooser.pickAFile();
p2.write( filename3 );
}
}// end