title: Displaying image object from controller in the browser
body: <p>I use playframework 2.2.1 with Java,<br>
  I am trying to pass BufferedImage or ByteArray or ByteArrayInputStream<br>
  to view template in order to display it in browser directly from memory,<br>
  without saving to server storage.<br>
  in my view template I request an image:  </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;img src="@{Application.getImage()}"/&gt;
  </code></pre>
  
  <p>my Application controller:  </p>
  
  <pre class="lang-java prettyprint-override"><code>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");  
  }
  </code></pre>
  
  <p>in generated html I get:  </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;img src="SimpleResult(200, Map(Content-Type -&amp;gt; image/jpg))"&gt;
  </code></pre>
  
  <p>I've found some info about this topic (<a href="https://stackoverflow.com/questions/8305853/how-to-render-a-binary-with-play-2-0">one</a>, <a href="https://groups.google.com/forum/#!topic/play-framework/5h5wh3eCiYo" rel="nofollow noreferrer">two</a>, <a href="https://stackoverflow.com/questions/4127876/send-generated-image-to-browser-using-play-framework">three</a>, <a href="https://groups.google.com/forum/#!topic/play-framework/Lk3miwcajHY" rel="nofollow noreferrer">four</a>),<br>
  but it is usually related to older versions, or Scala versions of play.<br>
  Please suggest anything or point to my mistake,<br>
  Thanks</p>