I'm working on a project for my comp sci class which deals with image processing. My group and I are going to vertically flip and rotate a picture 90 degrees. The first part of my code is the sample from my teacher that turns the photo gray. I'm able to compile my code, but I get the error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at Project6b.main(Project6b.java:10)
Press any key to continue...
I'm not even sure if what I've coded so far works, and I can't get this to run. Can anyone help me solve my runtime error?
import java.awt.image.*; import java.io.*; import javax.imageio.*; import java.awt.*; public class Project6b { public static void main (String args[]) throws Exception { // I would use these, if the program is finished. //grayscale(args[0], args[1]); //verticalFlip(args[0], args[1]); // I would comment the first two lines and //uncomment these for testing purposes. //grayscale("Vicc.jpg", "Vicc2.jpg"); verticalFlip("Vic.png", "Vic2.png"); } /*public static void grayscale(String originalImage, String convertedImage) throws Exception { BufferedImage bufferImg = ImageIO.read(new File(originalImage)); int r,g,b; Color color = null; for( int x = 0; x <bufferImg.getWidth(); x++) { for(int y = 0; y<bufferImg.getHeight(); y++) { int rgb = bufferImg.getRGB(x,y); color = new Color(rgb,true); r = color.getRed(); g = color.getGreen(); b = color.getBlue(); color = new Color((r+g+b)/3, (r+g+b)/3, (r+g+b)/3); bufferImg.setRGB(x,y, color.getRGB()); } } File outputfile = new File(convertedImage); ImageIO.write(bufferImg, "png", outputfile); } */ public static void verticalFlip(String originalImage, String convertedImage) throws Exception { BufferedImage bufferImg = ImageIO.read(new File(originalImage)); BufferedImage bufferImgOut = new BufferedImage(bufferImg.getWidth(),bufferImg.getHeight(), bufferImg.getType()); for (int x = 0; x < bufferImg.getWidth(); x++) { for (int y = 0; y < bufferImg.getHeight(); y++) { int px = bufferImg.getRGB(x, y); int destY = bufferImg.getHeight() - y - 1; bufferImg.setRGB(x, destY, px); } } File outputfile = new File(convertedImage); ImageIO.write(bufferImgOut, "png", outputfile); } //public static void Rotate(String originalImage, String convertedImage) throws Exception //{ //} }