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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:44:55+00:00 2026-05-27T01:44:55+00:00

I’m trying to access the raw pixel data of an image in Android. The

  • 0

I’m trying to access the raw pixel data of an image in Android.
The code looks something like this:

   Bitmap bitmap =  BitmapFactory.decodeFile("image.png"); 
   // assert valid input
   if ((bitmap.getConfig() == null) || bitmap.getConfig() == Config.ARGB_8888)
      throw new Exception("bad config");

  ByteBuffer buffer = ByteBuffer.allocate(4 * bitmap.getWidth() * bitmap.getHeight());
  bitmap.copyPixelsToBuffer(buffer);        
  return buffer.array();

How are the pixels in the linear 1D buffer.array() stored?

  1. First element is top-left pixel or bottom-left pixel (or something else)?
  2. Row-major (row after row) or column-major (column after column)?
  3. Channel order ARGB or BGRA?
  4. Row-major or column-major for each channel separately?
  5. Something else
  • 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-27T01:44:55+00:00Added an answer on May 27, 2026 at 1:44 am

    To get the offset into buffer.array() for a given pixel x,y in an image of size widthxheight with bytesPerPixel bytes per pixel, use this formula:

    offsetForPixel = (y * width + x) * bytesPerPixel
    

    In other words, the first element in the array is the top-left pixel, and the following elements are row-major. All data for a pixel are stored in adjacent bytes and are not spread out based on channel. This is the answer to 1, 2 and 4 above. Now let’s discuss 3, which is where things become complicated.

    What you get with Bitmap.copyPixelsToBuffer() is the raw bitmap data representation used by Android’s low-level drawing library skia. This has three significant consequences:

    • The channel order depends on endianness
    • The channels are premultiplied with alpha
    • How channels are packed into containing data types is configurable

    The last point makes it awkward to use Bitmap.copyPixelsToBuffer() at all if you want to inspect individual pixels, because you simply can’t know how skia has been configured to pack channels. As an experiment, try this code:

    int inputPixel = 0x336699cc;
    int[] pixels = new int[] { inputPixel };
    Bitmap bm = Bitmap.createBitmap(pixels, 1, 1, Config.ARGB_8888);
    ByteBuffer bb = ByteBuffer.allocate(4);
    bm.copyPixelsToBuffer(bb);
    Log.i("TAG", "inputPixel = 0x" + Integer.toHexString(inputPixel));
    for (int i = 0; i < 4; i++) {
        String byteString = "0x" + Integer.toHexString(bb.array()[i] & 0xff);
        Log.i("TAG", "outputPixel byte " + i + " = " + byteString);
    }
    

    When I run that, I get this output:

    I/TAG ( 1995): inputPixel = 0x336699cc
    I/TAG ( 1995): outputPixel byte 0 = 0x14
    I/TAG ( 1995): outputPixel byte 1 = 0x1f
    I/TAG ( 1995): outputPixel byte 2 = 0x29
    I/TAG ( 1995): outputPixel byte 3 = 0x33
    

    We can see that we are dealing with big endian, that the in-memory representation is pre-multiplied and that channels have been re-arranged from ARGB to RGBA (motivated in the skia source code by that that is the same in-memory representation as OpenGL).

    If you want to read the pixel data, I suggest you use Bitmap.getPixels() instead. There is some copying involved, but at least the API specifies how the returned data is formated.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.