Renderbinary() returns a blank or broken image in playframework 1.5.x. How to fix it

I have been trying to render an image on the UI using an API. I have the image stored in the database in the blob format and I have been using renderBinary function to render the image on the UI on API call but each time the image is returned blank or broken.
Here is the code snipet I have been using to render the image.

      InputStream is = new ByteArrayInputStream(imageBytes); // converted blob to byte[]
      BufferedImage bufferedImage = ImageIO.read(is);
      BufferedImage finalImage = resizeImage(bufferedImage, size, size);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ImageIO.write(finalImage, "jpeg", baos);
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      Http.Response.current().contentType = "image/jpeg";
      renderBinary(bais);

Does it work with the non-resized image?

no. Even with the non-resized image, it returns a blank image

The image format seems to be PNG instead of JPG, perhaps that’s the problem?

Anyway, if you read the (JPG) image from a file, does it render properly?

Example:


byte[] imageBytes = Files.readAllBytes(Play.applicationPath.toPath().resolve("app/public/image/unnamed.jpg"));
InputStream is = new ByteArrayInputStream(imageBytes); // converted blob to byte[]
BufferedImage bufferedImage = ImageIO.read(is);
// BufferedImage finalImage = resizeImage(bufferedImage, size, size);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// ImageIO.write(finalImage, "jpeg", baos);
ImageIO.write(bufferedImage, "jpeg", baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
Http.Response.current().contentType = "image/jpeg";
renderBinary(bais);

HI. Thanks for the answer. I tried this but it seemed to be not working for that also. On further debugging, I found that the issue was with the Compression logic that was applied for all the outgoing reponses. It compressed the image using gzip due to which the image was not rendered properly.
Resolved the issue by removing the Gzip compression logic for the response.