Search code examples
androidimagesocketsjavax.imageiojava-server

Need to display an image recieved through socket in android


Hey I need to display an image read from socket in my android application.The android application is basically a client it receives image from a java server.The java server writes a png file using ImageIO.write() function.I am new to android .Can somebody please help me


Solution

  • read the image first into byte[] array and then construct bitmap from bytes using BitmapFactory. It could look something like this:

    byte[] buffer = new byte[imgSize];
    
    //read all data to the buffer
    
    BitmapFactory.decodeByteArray(buffer, 0, buffer.length);