I'm trying to output a generated image using Play. I'm not sure if my issue is Play-specific or not. I'm trying to do the same thing this PHP code does:
header("Content-type: Image/png");
$map = imagecreatefrompng("$_SESSION[ROOT]/it/cabling/maps/${building}_$floor.png");
... // add annotations
imagepng($map);
It looks like I need to use renderBinary
, but I'm not sure how to get from a BufferedImage
to the InputStream
that renderBinary
wants as its argument.
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);
}