0

I have a bytearray of a tiff image. When I convert into the same format, image opens. But when I convert it into jpg, it doesn't (in Chrome, but works in IE). PS: I want to directly convert the bytearray to show image dynamically as per my requirement.

ByteArrayOutputStream bOutStream = new ByteArrayOutputStream(); 
bOutStream = < ... Tiff image Stream Received from my API Call... > 
byte[] chqImage = bOutStream.toByteArray(); 
response.setContentType("image/jpeg"); 
BufferedOutputStream output = null; 
output = new BufferedOutputStream(response.getOutputStream()); 
output.write( bOutStream.toByteArray()); 
output.flush();
DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44
  • 1
    Can you describe *how* you converted the image from tiff to jpeg? – PaulProgrammer Aug 29 '16 at 13:54
  • ByteArrayOutputStream bOutStream = new ByteArrayOutputStream(); bOutStream = < ... Tiff image Stream Received from my API Call... > byte[] chqImage = bOutStream.toByteArray() ; response.setContentType("image/jpeg"); BufferedOutputStream output = null; output = new BufferedOutputStream(response.getOutputStream()); output.write( bOutStream.toByteArray()); output.flush(); – Anant Gaggar Aug 29 '16 at 14:08
  • 1
    So, you've set the content type to `image/jpeg` but you haven't actually transformed the image into jpeg format -- you are still sending the unmodified tiff. – PaulProgrammer Aug 29 '16 at 14:49
  • okay thanks,let you know – Anant Gaggar Aug 30 '16 at 04:53

1 Answers1

0

You're going to need to actually translate the image itself from TIFF to JPEG. To do that, I recommend reviewing the ImageIO library in Java.

I feel like the javadoc for that library is pretty straightforward, so you should be OK there.

PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56