User:Simpsons contributor/ColorChange

package cellularautomaton;

import java.awt.Color; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException;

public class ColorChange {   public ImageHolder changeColors(ColorPair [] colors, ImageHolder imageIn) {       //Create new blank image int width = imageIn.getWidth; int height = imageIn.getHeight; ImageHolder imageOut = new ImageHolder(width, height); for(int x=0; x<width; x++) {           for(int y=0; y<height; y++) {               Color pixel = imageIn.getColor(x, y); boolean found = false; //Check if it matches any colors that need to be changed for(ColorPair pair : colors) {                   Color oldColor = pair.getOldColor; if(oldColor.equals(pixel) == true) imageOut.setColor(x, y, pair.getNewColor); found = true; }               //If the color hasn't been changed, restore to its old value if(found == false) imageOut.setColor(x, y, pixel); }       } //End of nested for loops return imageOut; }   public void changeFolder(ColorPair [] colors, String directory) throws FileNotFoundException, IOException {       //Check that openDirectory exists File dirTest = new File(directory); if(dirTest.isDirectory == false) throw new FileNotFoundException(directory + " does not exist"); //Get names of files from openDirectory String [] fileNames = dirTest.list; for(String fileName : fileNames) {           System.out.append("Performing color change on " + fileName); ImageHolder image = new ImageHolder(directory + fileName); image = changeColors(colors, image); image.save(directory + fileName, "png"); }   } }