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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:27:42+00:00 2026-05-25T13:27:42+00:00

Given an image that is in grayscale , how would I get the pixel

  • 0

Given an image that is in grayscale, how would I get the pixel values of the grayscale at that location?

This outputs temp as -16777216 (black) all the time.

public void testMethod()
{
    int width = imgMazeImage.getWidth();
    int height = imgMazeImage.getHeight();

    //Assign class variable as a new image with RGB formatting
    imgMazeImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
    for(int i=0; i < width; i ++){
        for(int j=0; j < height; j++)
        {
            //Grab and set the colors one-by-one
            inttemp = imgMazeImage.getRGB(j, i);
            System.out.println(temp);
        }
    }
}
  • 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-25T13:27:42+00:00Added an answer on May 25, 2026 at 1:27 pm

    you are creating a new blank image and assigning it to your class variable:

    imgMazeImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
    

    the pixels are created with a default value and its logical that they all have the same color (black) at the stage when you are printing them since you did not manipulate the color in any pixel yet.

    also, your code might fail if the width is not equal to the height. according to your for loops, i runs along width and j runs along height. therefore, you should change

    int temp = imgMazeImage.getRGB(j, i);
    

    to

    int temp = imgMazeImage.getRGB(i, j);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a function in Matlab that, given an image, will
I was given a data set that is essentially an image, however each pixel
I'm making a PHP image script that will create circles at a given radius.
I need to upload a given image using Amazon S3 I have this PHP:
Given a path and filename how can I get the Image object: Image image
I have a grayscale image from a photograph. I've determined that certain parts of
How do I make sense of the image data for a grayscale image given
Given a generated histogram that I got from an image I was wondering if
I have an image that was given to me in ASCII character format (from
I'm working on a bookmarklet that gives the full path to an image when

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.