Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Java graphic coordinates out of bounds?

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    1
    My Mood
    Nerdy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java graphic coordinates out of bounds?

    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


  2. #2
    Junior Member
    Join Date
    May 2011
    Posts
    2
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java graphic coordinates out of bounds?

    Have you tried changeing the vaules for the xStart on the sourcePictures? I am doing the same thing for an online class and im basically doing the same thing with the same pictures and after i get them to stick together i have to add color affects to it.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,604
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: Java graphic coordinates out of bounds?

    What are the values of xStart and y when the error occurs? Are they valid?

  4. #4
    Junior Member
    Join Date
    May 2011
    Posts
    2
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java graphic coordinates out of bounds?

    I ran the program i dont believe its the x or y coordinates. It says that the targetPixel.setColor(sourceColor); is whats outta of bounds. perhaps its because the pictures arnt in the right postions once ran?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,604
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: Java graphic coordinates out of bounds?

    Where are the classes Picture and Pixel defined?
    What does the setColor method do?

    i dont believe its the x or y coordinates.
    Print them out to be sure.
    Last edited by Norm; May 24th, 2011 at 03:46 PM.

Similar Threads

  1. [SOLVED] First assignment, clueless student, involving coordinates and distances
    By Kerrigan in forum Java Theory & Questions
    Replies: 7
    Last Post: March 10th, 2011, 03:52 PM
  2. arraylists to store coordinates for a snake applet
    By finalfantasyfreak15 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 19th, 2011, 09:21 PM
  3. how to adjust the size on a graphic component
    By Khoatic in forum AWT / Java Swing
    Replies: 8
    Last Post: November 19th, 2010, 10:28 PM
  4. Graphic angle
    By CoffeeBeans in forum Java Theory & Questions
    Replies: 1
    Last Post: August 22nd, 2010, 11:28 AM
  5. Graphic Environment Abstract Methods
    By striko_514 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 5th, 2010, 01:01 AM