loadBytes() not reading the entirety of JPEG file?

Hello @bbcwarrior,

I see no difference between the simple hex viewer and the contents of a JPG (or any other file) with a hex editor.

I tweaked your file a bit to show the 0x10 (16) lines per row:

byte b[] = loadBytes("Capture.JPG");

println("File size (bytes):", b.length);

for (int i = 0; i < b.length; i++) 
  {
  if ((i % 16) == 0 || i == 0) 
    {
    print( hex(i, 4) + " ");
    }

  int a = b[i] & 0xff;
  print(hex(a, 2) + " ");

  if (((i+1) % 16) == 0) 
    {
    println();
    }
  }

You may not be seeing everything in your console.

If you want to create an image editor then a hex editor will not work for a JPEG.
I suggest you do a bit of research on this point.

Resources:

:)

1 Like