A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Convert and display image from byte array
Joined: Sep 15, 2013
Sep 15, 2013 14:23:14
I have a method from a webservice that returns a bytearray that is an image and i want to display this as a response.
I tried create a jpg file and then display it but this doesn't work. The file is created but i cant displayed it.
arreglo = brailleText(request.getParameter("texto"),tamano); BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(arreglo)); File imageFile = new File("/home/antonio/services/magicsquare/image/braile.jpg"); ImageIO.write(bufferedImage,"jpg", imageFile); /// TODO output your page here out.println("<html>"); out.println("<head>"); out.println("<title>Servlet BrailleServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<img src=\"" + request.getContextPath() + "/image/braile.jpg\" />"); out.println("</body>"); out.println("</html>");
Does anyone know how to do this?
Author and ninkuma
Joined: Jan 10, 2002
Sep 15, 2013 15:52:23
If you want to return the image as the response, why are you writing HTML?
Do you want to return the image as the response? Or return an HTML page that contains the image?
I assume the former, but your code is trying to do the latter.
Asking smart questions
Books by Bear
I agree. Here's the link:
subject: Convert and display image from byte array
How can I resize an image from database table and show it
How save an image to file on HD and send to a client link to the file?
Servlet creating empty file on saving canvas image
Configuring JNDI for JavaBean in Tomcat 5
display image from bytearray
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013