Uncaught error fetching image with PixelGrabber

Discussion in 'Java' started by Alexandre, Apr 8, 2004.

  1. Alexandre

    Alexandre Guest

    public Contenu()
    {
    super();
    setVisible(true);
    setBounds(50,50,1024,768);
    setDoubleBuffered(true);
    Toolkit tk = Toolkit.getDefaultToolkit();
    fond = tk.getImage("solgalactic.jpg");
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(fond, 0);
    try{mt.waitForAll(); } catch(Exception e){e.printStackTrace();}
    int[] pix = new int[fond.getWidth(this)*fond.getHeight(this)];

    PixelGrabber pg = new PixelGrabber(fond, 0, 0,
    fond.getWidth(this),fond.getHeight(this), pix, 0,
    fond.getWidth(this)*fond.getHeight(this));

    //the bug comes in this try catch block
    try{pg.grabPixels();}catch(ArrayIndexOutOfBoundsException
    e){e.printStackTrace();}catch(Exception e){e.printStackTrace();}

    }

    While executing the previous code I get this blocking uncaught error.

    Uncaught error fetching image:
    java.lang.ArrayIndexOutOfBoundsException: 786432
    at java.awt.image.PixelGrabber.setPixels(PixelGrabber.java:563)
    at sun.awt.image.PixelStore32.replayLines(PixelStore32.java:41)
    at sun.awt.image.PixelStore.replay(PixelStore.java:224)
    at sun.awt.image.PixelStore.replay(PixelStore.java:153)
    at sun.awt.image.InputStreamImageSource.updateFromStore(InputStreamImageSource.java:282)
    at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:235)
    at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:221)
    at sun.awt.image.ImageFetcher.run(ImageFetcher.java:189)

    can anyone help me ?
    Alexandre, Apr 8, 2004
    #1
    1. Advertising

  2. Alexandre wrote:

    > PixelGrabber pg = new PixelGrabber(fond, 0, 0,
    > fond.getWidth(this),fond.getHeight(this), pix, 0,
    > fond.getWidth(this)*fond.getHeight(this));


    > can anyone help me ?


    Yes. The last parameter, int scansize, is "the distance from one row of
    pixels to the next in the array". In other words the width of the
    image. Take out the *fond.getHeight(this) and it should work just fine.

    On another note is there some reason you are not using the modern
    methods for reading image files and gathering pixel data? What are you
    ultimately going to do with this pixel data?

    --

    Knute Johnson
    email s/nospam/knute/
    Molon labe...
    Knute Johnson, Apr 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Riri

    PixelGrabber

    Riri, Jan 29, 2004, in forum: Java
    Replies:
    2
    Views:
    1,560
    Andrew Hobbs
    Jan 30, 2004
  2. Luc The Perverse

    Text to PixelGrabber

    Luc The Perverse, Mar 3, 2007, in forum: Java
    Replies:
    9
    Views:
    629
  3. buu

    PixelGrabber question

    buu, Aug 19, 2007, in forum: Java
    Replies:
    4
    Views:
    387
    Thomas Fritsch
    Aug 19, 2007
  4. Merlin
    Replies:
    0
    Views:
    96
    Merlin
    Sep 21, 2003
  5. BlueDeath

    Error: uncaught exception: null

    BlueDeath, Jan 26, 2004, in forum: Javascript
    Replies:
    0
    Views:
    101
    BlueDeath
    Jan 26, 2004
Loading...

Share This Page