<tfoot id='Wulo8'></tfoot>

    1. <small id='Wulo8'></small><noframes id='Wulo8'>

    2. <legend id='Wulo8'><style id='Wulo8'><dir id='Wulo8'><q id='Wulo8'></q></dir></style></legend>
      <i id='Wulo8'><tr id='Wulo8'><dt id='Wulo8'><q id='Wulo8'><span id='Wulo8'><b id='Wulo8'><form id='Wulo8'><ins id='Wulo8'></ins><ul id='Wulo8'></ul><sub id='Wulo8'></sub></form><legend id='Wulo8'></legend><bdo id='Wulo8'><pre id='Wulo8'><center id='Wulo8'></center></pre></bdo></b><th id='Wulo8'></th></span></q></dt></tr></i><div id='Wulo8'><tfoot id='Wulo8'></tfoot><dl id='Wulo8'><fieldset id='Wulo8'></fieldset></dl></div>

      • <bdo id='Wulo8'></bdo><ul id='Wulo8'></ul>

    3. 通过 Java Socket 读取图像文件

      Read Image File Through Java Socket(通过 Java Socket 读取图像文件)
      <i id='4DfBO'><tr id='4DfBO'><dt id='4DfBO'><q id='4DfBO'><span id='4DfBO'><b id='4DfBO'><form id='4DfBO'><ins id='4DfBO'></ins><ul id='4DfBO'></ul><sub id='4DfBO'></sub></form><legend id='4DfBO'></legend><bdo id='4DfBO'><pre id='4DfBO'><center id='4DfBO'></center></pre></bdo></b><th id='4DfBO'></th></span></q></dt></tr></i><div id='4DfBO'><tfoot id='4DfBO'></tfoot><dl id='4DfBO'><fieldset id='4DfBO'></fieldset></dl></div>
        <tbody id='4DfBO'></tbody>
      <legend id='4DfBO'><style id='4DfBO'><dir id='4DfBO'><q id='4DfBO'></q></dir></style></legend>

      <small id='4DfBO'></small><noframes id='4DfBO'>

        • <bdo id='4DfBO'></bdo><ul id='4DfBO'></ul>
              <tfoot id='4DfBO'></tfoot>

                本文介绍了通过 Java Socket 读取图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                这是我目前所拥有的,

                Socket clientSocket = new Socket(HOST, PORT);
                
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                
                InputStream is = socket.getInputStream();
                byte[] byteChunk = new byte[1024];
                
                int c = is.read(byteChunk);
                
                while (c != -1){
                    buffer.write(byteChunk, 0, c);
                    c = is.read(byteChunk);
                }
                
                BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(buffer.toByteArray()));
                

                我的代码的问题是 ImageIO.read() 返回 null.

                My problem with my code is ImageIO.read() returns null.

                当我打印 ByteArrayOutputStream 对象的内容时,我得到的是标题部分

                When I print the content of ByteArrayOutputStream object what i get is header part

                HTTP/1.1 200 OK
                Date: Fri, 30 Dec 2011 11:34:19 GMT
                Server: Apache/2.2.3 (Debian) ...........
                Last-Modified: Tue, 20 Dec 2011 19:12:23 GMT
                ETag: "502812-490e-4b48ad8d273c0"
                Accept-Ranges: bytes
                Content-Length: 18702
                Connection: close
                Content-Type: image/jpeg
                

                后跟一个空行加上许多不同字符的行,例如 $sU,e6~áP;....

                followed with a empty line plus many lines with different characters such as $sU,e6~áP;….

                我的问题又是 ImageIO.read() 函数返回 null.

                Again my problem is ImageIO.read() function returns null.

                提前致谢.

                推荐答案

                为什么你不想使用简单的 http URL 从主机获取图像?我的意思是:

                Why you don't want to use simple http URL to get image from host? I mean:

                URL imageURL = new URL("http://host:port/address");
                BufferedImage bufferedImage = ImageIO.read(imageURL);
                

                如果您想使用普通套接字,您必须手动解析 http 响应并从 http 回复中提取数据:读取/跳过标头,读取二进制数据并将其传递给 ImageIO.read(或寻求流以纠正位置并将流传递给 ImageIO.read).

                If you want to use plain socket you have to parse http response and extract data from the http reply manually: read/skip headers, read binary data and pass it to ImageIO.read (or seek stream to correct position and pass stream to ImageIO.read).

                这篇关于通过 Java Socket 读取图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Compiling C++ for the JVM(为 JVM 编译 C++)
                Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)
                  <bdo id='R5d7o'></bdo><ul id='R5d7o'></ul>
                  <legend id='R5d7o'><style id='R5d7o'><dir id='R5d7o'><q id='R5d7o'></q></dir></style></legend>
                    <tbody id='R5d7o'></tbody>
                    1. <i id='R5d7o'><tr id='R5d7o'><dt id='R5d7o'><q id='R5d7o'><span id='R5d7o'><b id='R5d7o'><form id='R5d7o'><ins id='R5d7o'></ins><ul id='R5d7o'></ul><sub id='R5d7o'></sub></form><legend id='R5d7o'></legend><bdo id='R5d7o'><pre id='R5d7o'><center id='R5d7o'></center></pre></bdo></b><th id='R5d7o'></th></span></q></dt></tr></i><div id='R5d7o'><tfoot id='R5d7o'></tfoot><dl id='R5d7o'><fieldset id='R5d7o'></fieldset></dl></div>

                      <tfoot id='R5d7o'></tfoot>
                    2. <small id='R5d7o'></small><noframes id='R5d7o'>