Your problem is writing to a stream and then reading an image from it. At the start of reading of the image, your position in stream is at the very end; so there is nothing to read, which throws an exception. Rewind the stream back to the beginning, reopen it.
You don't need to write bytes to the stream, they are already there. Use this constructor, with one parameter:
After that, just read the image.