java 如何通过套接字发送图像对象...?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1385649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:22:52  来源:igfitidea点击:

How send image object through socket...?

java

提问by user169258

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

我想通过套接字发送图像对象......不想将图像存储在发送方或接收方的计算机中......

回答by Martijn Courteaux

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());

回答by Brian Agnew

So what have you tried ?

那么你尝试了什么?

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

是一个关于使用 Java 进行客户端/服务器通信的教程。这从标准输入读取,但在您的实例中,您可能应该在图像对象上提供InputStream

回答by Eran Betzalel

Use thisserialization for an image object to send it through the socket.

对图像对象使用序列化以通过套接字发送它。