Sunday, March 20, 2011

How send image object through socket...?

I want to send image object through socket... Don't want to store image in sender or receivers computer...

From stackoverflow
  • So what have you tried ?

    This is a tutorial on client/server communication using Java. This reads from stdin, but in your instance you should probably provide an InputStream on your image object.

  • Use this serialization for an image object to send it through the socket.

  • Use this method:

      ImageIO.write(RenderedImage, String, OutputStream)
    

    Use in your situation:

    Sender

       BufferedImage image = ....;
       ImageIO.write(image, "PNG", socket.getOutputStream());
    

    Receiver

       BufferedImage image = ImageIO.read(socket.getInputStream());
    

0 comments:

Post a Comment