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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:43:16+00:00 2026-06-05T11:43:16+00:00

I got a doubt. When I obtain the pixels from a Bitmap in Android.

  • 0

I got a doubt. When I obtain the pixels from a Bitmap in Android. I’ve got an image loaded inside it, this image is a grayscale image. If I make a getPixels() and check the values I can see values with R != G != B.

I think I can check if it’s grayscale if the values of the three slides (R, G and B) got the same value, but I couldn’t be possible.
There is a way to verify it?

Lots of thanks!

  • 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-05T11:43:18+00:00Added an answer on June 5, 2026 at 11:43 am

    Let first off say that there are a couple of ways of accomplishing this.

    I would say get the size of the image using (something like)

    int myHeight = myImage.getHeight();
    int myWidth  = myImage.getWidth();
    

    I would say in this case you may also want to verify the Bitmap’ config as it could be one of 3 different formats

    ALPHA_8, ARGB_8888, or RGB_565
    

    You get the configuration using the

    myImage.getConfig()
    

    routine. We will get back to how this should be used later.

    Now that you know the size of the image you should run a dual loop structure as follows:

    boolean isGrayscaleImage = true;  // assume it is grayscale until proven otherwise
    
    for(int i = 0; i < myWidth; i++){
        for(int j = 0; j < myHeight; j++){
            int currPixel = myImage.getPixel(i, j);
    
            if( false == isGrayScalePixel(currPixel) ){
                isGrayscaleImage = false;
                break;
            }
        }
    }
    

    Back to HOW TO TEST IF THE PIXEL IS GRAYSCALE:
    If the image is stored as ALPHA_8 it really isn’t a grayscale image, but it could technically be converted to one by turning the image into an ARGB_8888 image and setting the Alpha value to 0xFF and each of the R, G, and B components to the alpha value provided within the original 8 bit ALPHA_8 based image.

    If the image is RGB_565 formatted, this is a bit trickier as you will have to pull apart the R, G, and B values into their own bytes by yourself using shift and MASKING operators. Once you have done this, it is essentially like processing the ARGB_8888 image (talked about below).

    For the ARGB_8888 image:
    the alpha channel SHOULD always be 0xFF.

    As you stated in your question a pixel is considered grayscale if R == G == B
    SO (Sample Code Might Look As Follows)

    boolean isGrayScalePixel(int pixel){
        int alpha = (pixel && 0xFF000000) >> 24;
        int red   = (pixel && 0x00FF0000) >> 16;
        int green = (pixel && 0x0000FF00) >> 8;
        int blue  = (pixel && 0x000000FF);
    
        if( 0 == alpha && red == green && green == blue ) return true;
        else return false;
    
    }
    

    There are optimizations that could be made, but I am trying to document the main algorithm for you.

    Hope this helps you out 🙂

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

Sidebar

Related Questions

While reading the answers to this question I got a doubt regarding the default
I got a doubt while doing this: class Logger { public static $log_INFO =
While reading this article, I got a doubt. I understood that while trasferring small
I got this doubt while writing some code. Is 'bool' a basic datatype defined
While reading ARM core document, I got this doubt. How does the CPU differentiate
I got this basic doubt. The STL header doesn't have .h extension. #include <vector>
I was going through k&r complicated declarations part.I got doubt about this particular declaration.
I don't have any hands on experience with graphics programming. I got this doubt
While I do a program, sometimes I've got this doubt. I have been using
Just a doubt regarding how JSF session management works I got a managedbean as

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.