我正在尝试使用 Play 输出生成的图像。我不确定我的问题是否与 Play 相关。我正在尝试执行与此 PHP 代码相同的操作:
header("Content-type: Image/png");
$map = imagecreatefrompng("$_SESSION[ROOT]/it/cabling/maps/${building}_$floor.png");
... // add annotations
imagepng($map);
看起来我需要使用renderBinary
,但我不知道如何从BufferedImage
to the InputStream
that 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)));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)