I use playframework 2.2.1 with Java,
I am trying to pass BufferedImage or ByteArray or ByteArrayInputStream
to view template in order to display it in browser directly from memory,
without saving to server storage.
in my view template I request an image:
<img src="@{Application.getImage()}"/>
my Application controller:
public static Result getImage() throws IOException{
BufferedImage image = ImageIO.read(new File("public/img/1.jpg"));
//some image manipulations
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
return ok(baos.toByteArray()).as("image/jpg");
}
in generated html I get:
<img src="SimpleResult(200, Map(Content-Type -> image/jpg))">
I've found some info about this topic (one, two, three, four),
but it is usually related to older versions, or Scala versions of play.
Please suggest anything or point to my mistake,
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…