Results 1 to 3 of 3
  1. #1
    Track13 is offline Member
    Join Date
    Nov 2012
    Posts
    11
    Rep Power
    0

    Default Syntax Error w/ my method

    Hello everyone, I am having trouble with this syntax error w/ my program.
    I am suppose to mirror a picture and copy that mirrored picture onto another picture.

    I have been reading through the textbook, rearranging my method, adding in parameters. I am just lost now. If someone can just point me into the right direction w/ this program I would greatly appreciate it.

    public void copyPic(Picture pict, int xStart, int yStart)
    {
    Pixel sourcePixel = null;
    Pixel targetPixel = null;

    for(int sourceX =0, targetX = xStart; sourceX < pict.getWidth(); sourceX++, targetX++)
    {
    for(int sourceY =0, targetY = yStart; sourceY < pict.getHeight(); sourceY++, targetY++)
    {
    sourcePixel = pict.getPixel(sourceX, sourceY);
    targetPixel= this.getPixel(targetX, targetY);
    targetPixel.setColor(sourcePixel.getColor());
    }
    }
    }

    public void mirrorPic(Picture pict)
    {
    int height = this.getHeight();
    int mirrorPoint = height / 2;
    Pixel topPixel = null;
    Pixel bottomPixel = null;

    Pixel sourcePixel = null;
    Pixel targetPixel = null;

    for(int sourceX =0, targetX =100; sourceX < pict.getWidth(); sourceX++, targetX++)
    {
    for(int sourceY =0, targetY = 145; sourceY < pict.getHeight(); sourceY++, targetY++)
    {
    sourcePixel = pict.getPixel(sourceX, sourceY);
    targetPixel = this.getPixel(targetX, targetY);
    targetPixel.setColor(sourcePixel.getColor());

    for(int x =0; x < pict.getHeight(); x++)
    {
    for(int y =0; y < mirrorPoint; y++)
    {
    topPixel = pict.getPixel(x, y);
    bottomPixel = this.getPixel(x,height - 1 - y);
    bottomPixel.setColor(topPixel.getColor());
    }
    }
    }
    }
    }

    public static void main (String[] args)
    {
    FileChooser.setMediaPath("C:/Users/runner/Documents/mediasources/");
    String backgroundFileName = FileChooser.pickAFile();
    Picture background = new Picture(backgroundFileName);
    Picture flower = new Picture(FileChooser.pickAFile());

    background.copyPic(flower, 10, 10);
    background.explore();
    background.mirrorPic(flower);
    background.show();
    }

    This is the syntax error: ------> java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
    at sun.awt.image.ByteInterleavedRaster.getDataElement s(Unknown Source)
    at java.awt.image.BufferedImage.getRGB(Unknown Source)
    at SimplePicture.getBasicPixel(SimplePicture.java:259 )

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Syntax Error w/ my method

    Hello and welcome! Please use [code][/code] tags when posting code so we can easily read it!

    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default Re: Syntax Error w/ my method

    Why have you abandoned your other thread? Help to rotate a pic 180 degrees (upside down)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Simple Syntax Error(s)
    By Vinx in forum New To Java
    Replies: 2
    Last Post: 05-18-2012, 02:55 AM
  2. No more syntax error
    By ideyatech in forum Java Software
    Replies: 2
    Last Post: 04-22-2010, 04:20 AM
  3. how to write method syntax ?
    By Bader in forum New To Java
    Replies: 2
    Last Post: 03-14-2010, 05:58 PM
  4. how to solve syntax error
    By pro85 in forum Java Applets
    Replies: 5
    Last Post: 04-06-2009, 11:20 AM
  5. syntax error
    By gabriel in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 03:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •