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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:40:27+00:00 2026-06-09T09:40:27+00:00

I am trying to do some simple image filtering using androids ndk and seem

  • 0

I am trying to do some simple image filtering using androids ndk and seem to be having some issues with getting and setting the rgb values of the bitmap.

I have stripped out all the actual processing and am just trying to set every pixel of the bitmap to red, but I end up with a blue image instead. I assume there is something simple that I have overlooked but any help is appreciated.

static void changeIt(AndroidBitmapInfo* info, void* pixels){
int x, y, red, green, blue;

for (y=0;y<info->height;y++) {


     uint32_t * line = (uint32_t *)pixels;
        for (x=0;x<info->width;x++) {

            //get the values
            red = (int) ((line[x] & 0xFF0000) >> 16);
            green = (int)((line[x] & 0x00FF00) >> 8);
            blue = (int) (line[x] & 0x0000FF);

            //just set it to all be red for testing
            red = 255;
            green = 0;
            blue = 0;

            //why is the image totally blue??
            line[x] =
              ((red << 16) & 0xFF0000) |
              ((green << 8) & 0x00FF00) |
              (blue & 0x0000FF);
        }

        pixels = (char *)pixels + info->stride;
    }
}

How should I both get and then set the rgb values for each pixel??

Update with answer
As pointed out below it seems that little endian is used, so in my original code I just had to switch the red and blue variables:

static void changeIt(AndroidBitmapInfo* info, void* pixels){
int x, y, red, green, blue;

for (y=0;y<info->height;y++) {


     uint32_t * line = (uint32_t *)pixels;
        for (x=0;x<info->width;x++) {

            //get the values
            blue = (int) ((line[x] & 0xFF0000) >> 16);
            green = (int)((line[x] & 0x00FF00) >> 8);
            red = (int) (line[x] & 0x0000FF);

            //just set it to all be red for testing
            red = 255;
            green = 0;
            blue = 0;

            //why is the image totally blue??
            line[x] =
              ((blue<< 16) & 0xFF0000) |
              ((green << 8) & 0x00FF00) |
              (red & 0x0000FF);
        }

        pixels = (char *)pixels + info->stride;
    }
}
  • 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-09T09:40:29+00:00Added an answer on June 9, 2026 at 9:40 am

    It depends on the pixel format. Presumably your bitmap is in RGBA. So 0x00FF0000 corresponds to the byte sequence 0x00, 0x00, 0xFF, 0x00 (little endian), that is blue with transparency 0.

    I am not an Android developer so I don’t know if there are helper functions to get/set color components or if you have to do it yourself, based on the AndroidBitmapInfo.format field. You’ll have to read the API documentation.

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

Sidebar

Related Questions

I was trying to place some simple effects on an image using HBox using
I'm very new to SIMD/SSE and I'm trying to do some simple image filtering
I'm trying to implement some simple caching into my application and I'm having some
im having some problems trying to read a SQlite data base from flash using
I'm trying to replicate some image filtering software on the Android platform. The desktop
I'm trying to write some simple code to resize an image, and I am
I am trying to do some simple image zooming and panning with Android and
I'm trying to convert some simple .htaccess rewrites into web.config xml; all is well
I am trying to write some simple code which will read a text file
I'm trying to do some simple things in C and I'm confused. The program

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.