title: Java: How To Convert Image to Byte[]
body: <p>I'm having an image in Database in bytearray format. I want to display on browser. I don't know how to write Image using OutputStream. Here is my code.</p>
  
  <pre><code>   byte[] imageInBytes = (byte[]) obj; // from Database
      InputStream in = new ByteArrayInputStream(imageInBytes);
      Image img = ImageIO.read(in).getScaledInstance(50, -1, Image.SCALE_SMOOTH);
  
  
      OutputStream o = resp.getOutputStream();    // HttpServletResponse
      o.write(imgByte);
  </code></pre>