0

The task is to take a picture, read all its bytes and then write additional 15 zero bytes after each non-zero byte from original file. Example: it was B1,B2,...Bn and after it must be B1,0,0,..0,B2,0,0..,Bn,0,0..0. Then I need to save/replace new picture. In general I assume I can use something like ReadAllBytes and create an array of bytes, then create new byte[] array and take one byte from file, then write 15 zero bytes, then take second byte and etc. But how can I be sure that it is working correctly? I'm not familiar with working with bytes and if I try to print bytes that I've read from file it shows some random symbols that don't make any sense which leaves the question: am I doing it right? If possible, please direct me to right approach and the functions that I need to use to achieve it, thanks in advance!

Mark
  • 27
  • 3

1 Answers1

0

See How to convert image to byte array for how to read the image.

It seems that you'd like to be able to visually see the data. For debugging purposes, you can show each byte as a hex string which will allow you to "see" the hex values of each element of your array.

public string GetBytesAsHexString(byte[] bArr)
{
    StringBuilder sb = new StringBuilder();

    if (bArr != null && bArr.Length > 0)
    {
        for (int i = 0; i < bArr.Length; i++)
        {
            sb.AppendFormat("{0}{1}", bArr[i].ToString("X"), System.Environment.NewLine);
            //sb.AppendFormat("{0}{1}", bArr[i].ToString("X2"), System.Environment.NewLine);
            //sb.AppendFormat("{0}{1}", bArr[i].ToString("X4"), System.Environment.NewLine);
        }
    }

    return sb.ToString();
}
Tu deschizi eu inchid
  • 4,117
  • 3
  • 13
  • 24