0

Im trying to get all bytes from a jpg file and manipulate it just as a fun practice. im getting each byte and subtracting it from 1 and then add that result to another byte array

    byte[] f = File.ReadAllBytes("aaa.jpg");
    byte[] fo = null;
    for(int i = 0;i<=f.Length;i++)
    {
        fo[i] = (byte)(f[i] - 1);
    }
    MessageBox.Show("done");

but im getting an error : Object reference not set to an instance of an object. its on line 5 and i don't really understand whats the problem

1 Answers1

0

You need to instantiate fo byte[] array. At the first iteration of your loop, you are accessing indexer property. Since indexer property belongs to an object, you are getting Object reference null exception, because array isn't instantiated.

byte[] fo = new byte[f.Length];
Darjan Bogdan
  • 3,780
  • 1
  • 22
  • 31