Those 4 bytes are the extra int -1.
I think you need some way to limit yout read loop to just read the right number of bytes from the input stream (ie the total bytes value that you read at the beginning) to create the image. Eg create a byte array of the right size (like you do in the server) and read into that in one go.
(I'm having to make this up as I go along because personally I've never done it this way, I have always used ObjectOutputStream/ObjectInputStream or XML to send stuff like this over a Socket.)