I have a simple black & white .bmp file and i would like to convert it through C# into a series of 0s and 1s, excluding the file headers and padding. The image is 32x32 pixels and this is what I have tried so far, but i couldn't remove the padding and header informations.
public BitArray imageToBinaryArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
bool[] arr = new bool[50000000];
int i = 0;
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
BitArray bitarray = new BitArray(ms.ToArray());
return bitarray;
}
private void readImage()
{
BitArray data;
string path = @"C:\Users\me\dummy.bmp";
Image Dummy = Image.FromFile(path);
data = imageToBinaryArray(Dummy);
var sb = new StringBuilder();
for (int i = 0; i < data.Count; i++)
{
char c = data[i] ? '1' : '0';
sb.Append(c);
}
string s = sb.ToString();
Console.WriteLine(s);
}
You can see below the figure i want to translate.
This is what i want to print:
00000000000000000000000000000000
11111111111111111111111111111111
01010101010101010101010101010101
10101010101010101010101010101010
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
00000000000000000000000000000000
00000000000000000000000000000001
00000000000000000000000000000011
00000000000000000000000000000111
00000000000000000000000000001111
11111111111111111111111111111111
11110000000000000000000000000000
11100000000000000000000000000000
11000000000000000000000000000000
10000000000000000000000000000000
00000000000000000000000000000000
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
Thanks in advance to everyone who will try to help me!