Click here to Skip to main content
15,849,615 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have written a test program and loaded a PNG image into it,

https://dotnetfiddle.net/XHwp7o

Pixel format = 32 bit color
Resolution of the Bitmap,
Width = 512 pixels
Height = 512 pixels
Stride of the Bitmap = 2048 pixels
Offset or Padding = (Stride - Width) = (2048 - 512) = 1336 pixels.
Size of the 1D byte array = 1048576 bytes

What would be the dimensions if we convert the Bitmap to a 2D array?

How can I convert a 1D byte array of a Bitmap into a 2D byte array of the same Bitmap?

What I have tried:

https://dotnetfiddle.net/XHwp7o
Posted
Updated 6-Jul-16 19:47pm

1 solution

Firstly, there are a few things to note in your report of the bitmap attributes:

1. Stride is usually reported in bytes, not pixels.
2. Each pixel is 4 bytes (32 bits).
3. This means that your offset or padding will be 0 (2048 bytes - 512*4 bytes).

Each row of your bitmap will be 512 * 4 = 2018 bytes, and there will be 512 rows. This means that it is simply a case of copying each sequential 2048 bytes of your 1D byte array into each row of the 2D array.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900