Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:54:05+00:00 2026-06-15T06:54:05+00:00

I have this kind of method: public void SaveImageOntoObject(String filepath) throws IOException { BufferedImage

  • 0

I have this kind of method:

public void SaveImageOntoObject(String filepath) throws IOException {


      BufferedImage image = ImageIO.read(getClass().getResourceAsStream(filepath));
      this.width = image.getWidth();
      this.height = image.getHeight();
      this.ResetPointInformation();
      for (int row = 0; row < width; row++) {
         for (int col = 0; col < height; col++) {
            this.PointInformation[row][col] = new Color(image.getRGB(col, row));
        }
     }
  }

It takes the filepath of an image as input, converts the RPG Value of each pixel into a Color Object and then stores it into the two-dimensional Array PointInformation of the Object the Method was called onto.

Now to my problem:

While some pictures like this one:

enter image description here

Work like a charm, others like this:

enter image description here

Let me end up with the error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:318)
at java.awt.image.BufferedImage.getRGB(BufferedImage.java:888)
at Drawing.Object2D.SaveImageOntoObject(Object2D.java:75)** (that's the class whose object's my method works on)

Why is that like that? It seems like Java is not able to convert certain RGB values into Colors?

Could you tell me how I can make it work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:54:07+00:00Added an answer on June 15, 2026 at 6:54 am

    The error message actually says it: “index out of bounds”. It seems, that you confused your coordinates and their bounds. getRGB takes the parameters x (range 0 .. width) as first, and y (range 0 .. height) as second.

    this.width = image.getWidth();
    this.height = image.getHeight();
    
    for (int row = 0; row < height; row++) {        // swapped the ...
        for (int col = 0; col < width; col++) {     // ... bounds
            this.PointInformation[row][col] = new Color(image.getRGB(col, row));
        }
    }
    

    Your first example has width = height, so that the problem doesn’t show.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a method public void Foo(string bar) that the caller should
I have this method that calculates some statistics: public void calculateAverage(int hour){ if (hour
I have this kind of question. In my form, i got this as a
I have this kind of node in my xml document: <parent ...> <a .../>
I have this kind of code below, how can I bind the visibility of
I have this kind of setup : Overridden BaseRunserverCommand that adds another option (--token)
I have this kind of table, it has many rows and each row has
I used to have this kind of simple JSON data and I could successfully
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
guys i have arrays in which i have to match this kind of text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.