What happens if you save that picture into file from the stream itself using SaveToFile method and then loading the image from file? Do you still get the same error?

Also does SaveImageToStream method moves the stream position to 0 before saving the data or does it just add the image to the end of the stream?

Similar question for method AddMaterial. Does it automatically moves the stream position to 0 before reading the data?