Hey guys, I'm working on a program that'll let me stitch some pictures together so that I can make a panorama with a few different images. But every time I run the program, it gives me this error:
java.lang.ArrayIndexOutOfBoundsException:
Coordinate out of bounds! (in sun.awt.image.IntergerInterleavedRaster)
and in the terminal window:
java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.IntegerInterleavedRaster.getDataElem ents(IntegerInterleavedRaster.java:202)
at java.awt.image.BufferedImage.getRGB(BufferedImage. java:871)
at SimplePicture.getBasicPixel(SimplePicture.java:300 )
at Pixel.getAlpha(Pixel.java:72)
at Pixel.setColor(Pixel.java:212)
at Panorama.panorama(PanoramaTester.java:21)
at Panorama.panoramaMaker(PanoramaTester.java:39)
at PanoramaTester.main(PanoramaTester.java:168)
Well here is my code(and in theory it should work, I believe):
import java.awt.*; //import the awt graphics package
class Panorama
{
Panorama()
{
}
public static void panorama(Picture sourcePicture,Picture targetPicture,Pixel sourcePixel,Pixel targetPixel,Color sourceColor,Color targetColor,int xStart)
{
for(int y = 0; y < sourcePicture.getHeight(); y++)
{
for(int x = 0; x < sourcePicture.getWidth(); x++)
{
sourcePixel = sourcePicture.getPixel(x,y);
sourceColor = sourcePixel.getColor();
targetPixel = targetPicture.getPixel(xStart,y);
targetPixel.setColor(sourceColor);
xStart++;
}
}
}
public static void panoramaMaker()
{
Picture targetPicture = new Picture(1150,400);
targetPicture.setAllPixelsToAColor(Color.BLACK);
Pixel sourcePixel = null;
Pixel targetPixel = null;
Color sourceColor = null;
Color targetColor = null;
Picture sourcePicture = new Picture("Mars1.jpg");
int xStart = 0;
panorama(sourcePicture,targetPicture,sourcePixel,t argetPixel,sourceColor,targetColor,xStart);
Picture sourcePicture2 = new Picture("Mars2.jpg");
xStart += 230;
panorama(sourcePicture2,targetPicture,sourcePixel, targetPixel,sourceColor,targetColor,xStart);
Picture sourcePicture3 = new Picture("Mars3.jpg");
xStart += 230;
panorama(sourcePicture3,targetPicture,sourcePixel, targetPixel,sourceColor,targetColor,xStart);
Picture sourcePicture4 = new Picture("Mars4.jpg");
xStart += 230;
panorama(sourcePicture4,targetPicture,sourcePixel, targetPixel,sourceColor,targetColor,xStart);
Picture sourcePicture5 = new Picture("Mars5.jpg");
xStart += 230;
panorama(sourcePicture5,targetPicture,sourcePixel, targetPixel,sourceColor,targetColor,xStart);
//sourcePicture.show();
targetPicture.show();
targetPicture.write("NewMars.jpg");
}
}
I also have a couple other methods that contain effects that I'll apply to the panorama image later. I'm sure I'm making some dumb beginner's mistake, but I welcome all comments and answers.
Thanks in advance!
Joshua