No, SizeOf would return the size of a pointer (that is 4 bytes), I'd suggest when writing JPGs do: keep current Position of the stream, skip 8 bytes, write the JPG, keep the new Position, seek back to the old position and write the new position there, and finally seek to the end of the stream. Looks like a bug.