【问题标题】:Java obtain image, check mime type, convert to png and return that imageJava 获取图像,检查 mime 类型,转换为 png 并返回该图像
【发布时间】:2011-05-11 18:33:35
【问题描述】:

我正在尝试构建一个 java servlet 以从 URL 获取图像,检查它的 mime 类型并在必要时对其进行转换,然后返回该图像。 我应该使用什么对象,你能提供一些专门用于获取图像并返回它的例子吗?

非常感谢

【问题讨论】:

    标签: java image return mime-types


    【解决方案1】:

    只需使用JAI (intro reference):

    URL url = "// URL of the remote image to be read //";
    RenderedImage original = JAI.create("url", url);
    JAI.create("encode", original, response.getOutputStream(), "png");
    

    其中responseHttpServletResponse。请注意,不需要检查 mime 类型,JAI 会做一些必要的事情来弄清楚如何在幕后读取图像。

    【讨论】:

      猜你喜欢
      • 2013-09-13
      • 2013-03-28
      • 2017-12-06
      • 2016-09-04
      • 1970-01-01
      • 2013-12-20
      • 2011-02-01
      • 2014-10-07
      • 1970-01-01
      相关资源
      最近更新 更多