简体   繁体   English

如何在java中从输入流中读取png图像

[英]How to read png images form inputstream in java

There are 2 applications. 有2个申请。 One application act as server and sends continuously screen shot of desktop by using the following code. 一个应用程序充当服务器并使用以下代码连续发送桌面的屏幕截图。

Robot robot=new Robot();
OutputStream os;
BufferedImage image = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(image, "png", os);

The second application is Android application acts a client application and has to read continuously the above image stream from inputstream. 第二个应用程序是Android应用程序作为客户端应用程序,并且必须从输入流连续读取上面的图像流。

Could please help me to read the png images from inputstream in the client application. 请帮我在客户端应用程序中从inputstream读取png图像。

Thanks & Regards Mini. 谢谢和问候迷你。

In client application, read the InputStream via Socket.getInputStream() method. 客户端应用程序中,通过Socket.getInputStream()方法读取InputStream。

 BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
 BufferedImage image = ImageIO.read(in);

Android SDK does not support the method ImageIO.read(). Android SDK不支持ImageIO.read()方法。 Even if you can compile your code, your android application will get crashed and have error about missing libraries like this: 即使你可以编译你的代码,你的android应用程序也会崩溃,并且有关于缺少这样的库的错误:

could not find method javax.imageio.imageio.read 找不到方法javax.imageio.imageio.read

What I suggest is using bitmapping instead of this... 我建议使用位图而不是这个......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM