You can convert the bit to byte array using C# built in function
BitArray ba = new BitArray(8);
ba[3] = true;
byte[] bar = new byte[ba.Length / 8];
ba.CopyTo(bar, 0); // bit array to byte array
Or
public byte[] getBitToByteArray(BitArray ScratchPadBitArray)
{
int byteArrayLength=ScratchPadBitArray.Length / 8;
byte[] ScratchPadByteArray = new byte[byteArrayLength];
for (int row = 0; row < byteArrayLength; row++)
{
ScratchPadByteArray[row] = 0;
for (int column = 0; column < 8; column++)
{
ScratchPadByteArray[row] += (byte)(Math.Pow(2, 7 – column) * Convert.ToInt32(ScratchPadBitArray[column + (row * 8)]));
}
}
return ScratchPadByteArray;
}
public byte[] getBitToByteArray()
{
BitArray ScratchPadBitArray = this.pixelBitArray;
int byteArrayLength = ScratchPadBitArray.Length / 8;
byte[] ScratchPadByteArray = new byte[byteArrayLength];
for (int row = 0; row < byteArrayLength; row++)
{
ScratchPadByteArray[row] = 0;
for (int column = 0; column < 8; column++)
{
ScratchPadByteArray[row] += (byte)(Math.Pow(2, 7 – column) * Convert.ToInt32(ScratchPadBitArray[column + (row * 8)]));
}
}
return ScratchPadByteArray;
}