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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:40:47+00:00 2026-06-01T16:40:47+00:00

I have a getPixelColour function: Color getPixelColor(int x, int y) { if(mazeImage == null)

  • 0

I have a getPixelColour function:

Color getPixelColor(int x, int y) {
    if(mazeImage == null) System.out.println(":(");
    int pixel = mazeImage.getRGB(x, y);
    int  red = (pixel & 0x00ff0000) >> 16;
    int  green = (pixel & 0x0000ff00) >> 8;
    int  blue = pixel & 0x000000ff;
    return new Color(red,green,blue);
}

For example a pixel is black, and System.out.println(getPixelColor(x,y) + " " + Color.BLACK);
writes java.awt.Color[r=0,g=0,b=0] java.awt.Color[r=0,g=0,b=0]

But getPixelColor(x,y) == Color.BLACK returns false. What’s wrong with it?

  • 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-01T16:40:48+00:00Added an answer on June 1, 2026 at 4:40 pm

    You are comparing two different Color objects which will return false (i.e., two different objects at different memory locations).

    If you wish to properly compare them, use equals():

    getPixelColor(x, y).equals(Color.BLACK);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have someone tried out DeCAL in Delphi 2009? I'm thinking about upgrading from 2007,
have Googled the cr*p out of this one so apologies if the answer is
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have a n-tire web application and search often times out after 30 secs. How
I have a problem with finding the current color under the cursor. My code:
Have you any idea how to find out if spell check suggestions dialog is
Have just started converting an existing job tracking system into an ASP.NET MVC application.
Have following kernel function: private static String programSource = __kernel void sampleKernel(__global float *Y,
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =

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.