java - 使用 Play 框架将生成的图像发送到浏览器

标签 java image-processing playframework

我正在尝试使用 Play 输出生成的图像。我不确定我的问题是否是特定于 Play 的。我正在尝试做与此 PHP 代码相同的事情:

header("Content-type: Image/png");
$map = imagecreatefrompng("$_SESSION[ROOT]/it/cabling/maps/${building}_$floor.png");
... // add annotations
imagepng($map);

看起来我需要使用 renderBinary,但我不确定如何从 BufferedImageInputStream renderBinary 想要作为它的参数。

Application.map Action :

public static void map(String building_code, String ts_code) throws IOException {
    BufferedImage image = ImageIO.read(new File("public/images/maps/" + building_code + "_" + ts_code.charAt(0)));
    ... // Overlay some additional information on the image
    // do some sort of conversion
    renderBinary(inputStream);
}

最佳答案

有许多 renderBinary 方法,其中一个只是将 File 作为参数。 参见 http://www.playframework.org/documentation/api/1.1/play/mvc/Controller.html#renderBinary(java.io.File )

因此,您的代码需要尽可能简单

public static void map(String building_code, String ts_code) throws IOException {
    renderBinary(new File("public/images/maps/" + building_code + "_" + ts_code.charAt(0)));
}

关于java - 使用 Play 框架将生成的图像发送到浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4127876/

相关文章:

java - Play Framework,OneToOne 关系不起作用

java - 无法使用 Java API 创建 JIRA 问题

java - 调试测试,需要建议

android - 获取线程导致 Android 的另一个 Activity

Python:将 RAW 图像转换为 PNG

intellij-idea - 创建旧的 Play 2.3.1 框架(当前是 2.4.3)

scala - 如何在 scala playframework 2.2 中的 mysql 中存储加密密码?

java - ActiveMQ将特定队列消息移到不同服务器上的不同队列

java - 使用 AND 或 OR 条件手动构建 SQL 查询时出现 MySql 语法错误异常

c++ - 均衡 HSV 图像的直方图