0

I want to make a int32[] bits array with an original bitmap

Is there any way to create a int32[] that including the original bitmap?

so that I can read the pixel using

int index = x + (y * Width);
    int col = Bits[index];
    Color result = Color.FromArgb(col);

instead of the

bitmap.GetPixel()
jazb
  • 5,498
  • 6
  • 37
  • 44
lescper
  • 19
  • 4

2 Answers2

0

As shown at Convert a bitmap into a byte array you can use ImageConverter or a MemoryStream.

tymtam
  • 31,798
  • 8
  • 86
  • 126
-1

Assuming you have the path to the file and you are sure that the file format is one byte per color you can just read the bytes from the file like this:

var Bits = System.IO.File.ReadAllBytes("path_to_the_image");

Bits will be an array of bytes so no explicit conversion will be needed to be used on the Color.FromArgb() function.

Guido Zanon
  • 2,939
  • 26
  • 31
  • question was about `int32[]`, not `byte[]` – vasily.sib Dec 17 '18 at 03:25
  • No one said there was a file. @vasily, getting `int[]` from `byte[]` is not an issue, just call `Buffer.BlockCopy`. – Ben Voigt Dec 17 '18 at 03:28
  • `System.IO.File.ReadAllBytes("path_to_the_image");` read all bytes from file in `path_to_the_image` path. Ok, you convert `byte[]` to `int[]` with `Buffer.BlockCopy`, but question was abour pixel data, not file data. Now, how do you handle file formats? How do you strip all image headers and meta info from your `int[]`? – vasily.sib Dec 17 '18 at 03:33