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

  • Home
  • SEARCH
  • 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 6656739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:40:49+00:00 2026-05-26T01:40:49+00:00

I am writing a small program in java which will draw a path on

  • 0

I am writing a small program in java which will draw a path on an image. To do so, I have the following code

while(!path.isEmpty())
{
    Position p = path.poll();
    image.setRGB(p.getX(),p.getY(),Color.red.getRGB());
}

Where path is a Queue of objects which old the X and Y coordinates and image is a standard BufferedImage (from ImageIO.read). This code is just meant to draw a red pixel on every pixel of the image that does is in the queue. Instead of Red though, when I write this image to file I get a gray color.

The diagonal gray line SHOULD be Red...

The return value of Color.red.getRGB is 0xFFFF0000. When I do a getRGB on the pixel after I set it to red, I get back 0xFF7F7F7F.

I am relatively new to Java and have no idea why this is happening. Any help would be greatly appreciated.

If it makes a difference, the image is from a .bmp file.

  • 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-26T01:40:49+00:00Added an answer on May 26, 2026 at 1:40 am

    It could be that you’re using a BufferedImage that’s a grayscale type, or a type that maps those sRGB values to a gray color.

    Generally, you have one of two possibilities:

    1. If you’re initializing BufferedImage explicitly, check out either the imageType or the ColorModel arguments, depending on the constructor you’re using.
    2. If you’re initializing the image object through some factory method or otherwise indirectly, check out the value of the getType() method. The values are listed in the JavaDoc . If that’s a “correct” value (one of the RGB types), check out the return of getColorModel().

    Since you’re loading the image from a .bmp file, the 2nd one is probably your case.

    For info about color value conversion issues, see here and here.

    Generally, if you just want to learn about image handling in Java, I would suggest to use the second BufferedImage constructor with *TYPE_INT_ARGB* as the type for starters, and expand your code from that. From what I remember of my early Java days, learning image loading can be a bit tricky :).

    Also, you might want to read the official Java2D tutorial. It’s a quite good introduction to the topic.

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

Sidebar

Related Questions

When writing a Java program, do I have influence on how the CPU will
I'm writing a small program which will make a GET request to a server
I'm writing a small tool in C# which will need to send and receive
I'm writing a small agent in java that will play a game against other
As a Christmas gift I have written a small program in Java to calculate
I have been writing a small java application (my first!), that does only a
I'm writing a small program (a twitter client) in Java, aimed at Mac OS
I'm writing a small/beta testing program that will be put to use in my
I'm writing a small program which is to be used as a digital distribution
I am writing a small C++ program which passes a 2-D array (of complex

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.