【问题标题】:Display an image using jetty web server from byte array使用字节数组中的码头网络服务器显示图像
【发布时间】:2013-06-30 03:57:50
【问题描述】:

我有一个字节数组中的图像内容,在码头 servlet 类中。如何在浏览器中显示此图像?

【问题讨论】:

    标签: java jetty


    【解决方案1】:

    你的 sevlet 中会有类似的东西

    byte[] imageBytes = ...
    response.setHeader("Content-Type", "image/jpg");// or png or gif, etc
    response.setHeader("Content-Length", imageBytes.lenght);
    response.getOutputStream().write(imageBytes);
    

    【讨论】:

      【解决方案2】:

      此代码有效。感谢“大卫霍夫曼”。

      //data is the content of the image in binary
      response.setContentType("image/jpg");// or png or gif, etc
      response.setContentLength(data.length);
      response.getOutputStream().write(data);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多