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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:41:11+00:00 2026-06-15T04:41:11+00:00

I have to convert the pixels of a bitmap to short array. Therefore I

  • 0

I have to convert the pixels of a bitmap to short array. Therefore I want to:

  • get the bytes
  • convert the bytes to short

This is my source to get the bytes:

 public byte[] BitmapToByte(Bitmap source)
 {
     using (var memoryStream = new MemoryStream())
     {
         source.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp);
         return memoryStream.ToArray();
     }
 }

This is not returning the expected results. Is there another way to convert the data?

  • 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-15T04:41:12+00:00Added an answer on June 15, 2026 at 4:41 am

    Please explain your problem properly. “I’m missing bytes” is not something that can be solved. What data do you expect, and what do you see?

    Bitmap.Save() will return the data according to the specified format, which in all cases contains more than just the pixel data (headers describing width and height, color / palette data, and so on). If you just want an array of pixel data, you’d better look at Bimap.LockBits():

    Bitmap bmp = new Bitmap("c:\\fakePhoto.jpg");
    
    // Lock the bitmap's bits.  
    Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
    System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
    
    // Get the address of the first line.
    IntPtr ptr = bmpData.Scan0;
    
    // Declare an array to hold the bytes of the bitmap. 
    int bytes  = Math.Abs(bmpData.Stride) * bmp.Height;
    byte[] rgbValues = new byte[bytes];
    
    // Copy the RGB values into the array.
    System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
    

    Now the rgbValues array contains all pixels from the source bitmap, using three bytes per pixel. I don’t know why you want an array of shorts, but you must be able to figure that out from here.

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

Sidebar

Related Questions

I have the following function to convert a byte array of pixels into an
I have an array of bytes that correspond to a grayscaled bitmap (one byte->one
In my Android application I have pixels(69px) and I need to convert this pixels
Possible Duplicate: Convert a image to a monochrome byte array I have a monochrome
I have a date like this:- 20091023 i have to convert it to a
I have the following: byte[] pixels = new byte[28] { 0x00, 0x00, 0x30, 0x00,
I have used Bitmap class to convert tiff to Gif but it couldn't make
I have been trying to figure out a way to convert bitmap files into
I have a need to convert Pixels to Points in C#. I've seen some
Download source code here: http://www.eyeClaxton.com/download/delphi/ColorSwap.zip Yes, I want to convert something mostly blue to

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.