15,849,615 members
See more:
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

## Solution 1

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.