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 4265140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:35:00+00:00 2026-05-21T06:35:00+00:00

So, what I’m trying to do is run through a picture that is 1024×768

  • 0

So, what I’m trying to do is run through a picture that is 1024×768 (Or, popMap.getWidth x popMap.getHeight), grab the blue color of it, compare it to the highest blue so far, and if it’s more, that blue becomes the new ‘newBlue’. Basically, find the highest blue value in an image, closest to 255 blue.

Also, I’m attempting to store the blue value of the entire thing into an array popMapArray, which is a 2d array with 3 columns, storing [blueValue][x][y]. Which I will then sort, to get a list from high to low of the bluest values.

My problem, is that with the code below, it’s only storing into the array when column=767.

I get 1024 [blue,row,767], and then the rest are all [0,0,0]

Any clue why? Java, by the way.

for (int row = 0;  row < popMap.getWidth(); row++) 
    {
        for (int column = 0; column < popMap.getHeight(); column++)
        {
            System.out.println(column);
            //Find a Pixel
            int c = popMap.getRGB(row, column);
            int red = (c & 0x00ff0000) >> 16;
            //int  green = (c & 0x0000ff00) >> 8;
            //int  blue = c & 0x000000ff;
            // and the Java Color is ...
            Color color = new Color(red); 
            int newBlue = color.getBlue();
            int oldBlue = lastColor.getBlue();
            switch(popArrayRow)
            {
                case 0:
                {
                    arrayVar = newBlue;
                    popArrayRow = 1;
                    break;
                }
                case 1:
                {
                    arrayVar = row;
                    popArrayRow = 2;
                    break;
                }
                case 2:
                {
                    arrayVar = column;
                    popArrayRow = 0;
                    break;
                }
            }
            popArray[row][popArrayColumn] = arrayVar;
            //System.out.println(popArray[row][popArrayColumn]);
            switch(popArrayColumn)
            {
                case 0:
                {
                    popArrayColumn = 1;
                    break;
                }
                case 1:
                {
                    popArrayColumn = 2;
                    break;
                }
                case 2:
                {
                    popArrayColumn = 0;
                    break;
                }
            }


            if(newBlue > oldBlue)
            {
                startX = row;
                startY = column;
                //System.out.print(row);
                //System.out.print(",");
                //System.out.println(column);
                System.out.print("The oldBlue is ");
                System.out.println(oldBlue);
                lastColor = color;
            }



        }
    } 
  • 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-05-21T06:35:01+00:00Added an answer on May 21, 2026 at 6:35 am

    You didn’t show the declaration go popArray (as well as some other variables which I’m assuming are ints that are initialized to 0). You describe it as “a 2d array with 3 columns”. I’m guessing you’ve declared it as int[1024][3], so it has one row per row in popMap, then your 3 “columns” which are meant to store the blue value, the original x coordinate, and the original y coordinate.

    So first of all it is unclear how you expect to store one entry in this array for each pixel in the original image. But maybe my guess about how you declared it is wrong.

    In any case, each time through the inner loop you essentially want to set

    popArray[currentPixel] = {blueValue, origX, origY}

    but instead you are assigning only one of the three value each time through the loop. So you are doing something like

    popArray[0][0] = blueValue //first iteration; blueValue from row 0 col 0
    popArray[0][1] = 0 //second iteration; row from row 0 col 1
    popArray[0][2] = 2 //third iteration; column from row 0 col 2
    

    So hopefully you can already see that something is wrong, since you are populating “columns” that are supposed to go together with values from different iterations of the loop. Even worse, you then start overwriting those values on the next iteration of the inner loop (which will iterate a total of 768 times before row increments):

    popArray[0][0] = blueValue // fourth iteration; blueValue from row 0 col 4; overwrite value assigned on first iteration
    etc...
    

    Rather than using 3 array “columns” with different meanings to hold these data elements, it would be wise to make a class that holds the three values and makes clear what’s what. popArray would contain this object type. Furthermore, I would make it a List instead of an array since it is more flexible and you can simply call Collections.sort() on it at the end; or @jsegal has a good suggestion of using a data structure that sorts as the items are inserted. Which one is better might depend on what you want to do with them later.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

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.