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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:37:00+00:00 2026-06-04T12:37:00+00:00

I have a png file created with python PIL that contains an height map

  • 0

I have a png file created with python PIL that contains an height map (positive values).

The format is : single channel (grey level) at 16bit, thus 16 bit per pixel.

I read the file on android with BitmapFactory.decodeStream(<...data input stream...>);

I correctly get the size of the image through getWidth() and getHeight().

However when I loop though the pixels calling the getPixel(i,j) I obtain negative values, something like: -16776192 -16250872 -16250872 -16250872 -16250872 -16249848 ….

Instead I expect a positive value between 0 and 65535.

I discover that the value -16250872 in binary is 1111111111111111111111111111111111111111000010000000100000001000

This shows that the information relies on the first 16 least significant bits.

I tryed with getPixel(i,j)&0xffff and I obtain a plausible values, however I’m not sure about the endianess: should I to flip the 2 extracted bytes?

Is there a way to do it in more elegant and portable way this conversion ?

NOTE: the file is not a color (RGBA) PNG but a grey level PNG image with a single 16 bit value for each pixel.

  • 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-04T12:37:01+00:00Added an answer on June 4, 2026 at 12:37 pm

    I found a solution by myself using the consideration made in this post:
    Android: loading an alpha mask bitmap

    Basically, If you load directly a 16 bit greylevel PNG from bitmap factory the pixel format will be not correct. You need to use a RGBA 32 bit color format setting the pixel format to ARGB_8888. Then you have to get all the pixels with getPixel(i,j) and mask the integer value with 0xffff. In this way you will obtain the expected 16bit values.

    This is a part of the code that I’ve used:

    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inPreferredConfig= Bitmap.Config.ARGB_8888;
    Bitmap bmp=BitmapFactory.decodeStream(entity.getContent(),null,opt);
    int W=bmp.getWidth();
    int H=bmp.getHeight();
    int px;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
        {
              px= bmp.getPixel(j, i)&0x0000ffff;//in px you will find a value between 0 and 65535
              ...
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image (PNG file) that has an alpha channel that is set
I have a PNG file in a UIImageView, and next to that I have
I have an .aspx file that outputs an image using the following methods: Server.MapPath(somefile.png)
I have a PNG image that has an unsupported bitmap graphics context pixel format.
I have created a helper that requires some parameters and should upload a file,
i have created a icon in photoshop and its a png file i have
I have a image (png file) with opacity 35%, i want for example: Set
I have a directory containing a number of static file (*.png, *.css, etc). I
I have a png graphic that is put in the web page using raphael
I have created 3 files for the app icon: Icon.png, Icon-72.png, and Icon@2x.png. Icon@2x.png

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.