Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to convert 1D byte array to 2D byte array which holds a bitmap?
    primarykey
    data
    text
    <p>I have already used the LockBits and UnlockBits functions and takes the byte array of a Image into a 1D array. (considering only the black and white/binarized images)</p> <p>Is there any way of taking it to a 2D array (of the size image height and width)? so i can wirte the array into a ".txt" file and view it?</p> <p>The code i have used to take the image into 1D array is as below:</p> <pre><code>Public void function(Bitmap image){ { byte[] arr1D; byte[] arr2D; BitmapData data = image.LockBits(new Rectangle(0, 0, img_w, img_h), ImageLockMode.ReadOnly, image.PixelFormat); try { IntPtr ptr = data.Scan0; int bytes = Math.Abs(data.Stride) * image.Height; byte[] rgbValues = new byte[bytes]; arr1D = rgbValues; Marshal.Copy(ptr, rgbValues, 0, bytes); } finally { image.UnlockBits(data); } } </code></pre> <p>Since the image is binary, the values of the Byte array is from only 255 and 0.</p> <p>Instead of extracting the entire image to a 1D array, is there any method/code where i can extract pixel row by row to a 2D array, Where i can write it to a text file and see later on?</p> <p><em>Programming Language : <strong>C#</em></strong></p> <p>example: (if the value 255 is replaced with 1)</p> <p><em>result output:</em> 1D array: (6px X 6px image)</p> <pre><code>0 0 1 1 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 1 0 0 </code></pre> <p><em>expected output:</em> 2D array: (6px X 6px image)</p> <pre><code>0 0 1 1 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 1 0 0 </code></pre> <p><strong>Can someone please help me with the code for it in C#?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload