This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes display image from bytearray Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "display image from bytearray" Watch "display image from bytearray" New topic
Author

display image from bytearray

nikki sinha
Greenhorn

Joined: Jul 04, 2012
Posts: 14
hi,
i am trying to convert a byte array of image into image and want to display in JSP page. i am able to save the picture in any location but cant display it in the web page.

here is my code

byte[] decoded = //the decoded base64 string in bytes.

BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(decoded));
File imageFile = new File("E:/profile.jpg");
ImageIO.write(bufferedImage,"jpg", imageFile);

this is working fine... the image gets store in the given location. but when i pass it through outputstream, it does not print it in the JSP page.

byte[] decoded = //the decoded base64 string in bytes.

BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(decoded));
OutputStream out = response.getOutputStream();
ImageIO.write(bufferedImage, "jpg", out);
out.flush();
out.close();

how can i print it in a new jsp file.....

please help...
thank you...

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12683
    
    5
Exactly how does the IMG tag in the HTML written by the JSP refer to the image source?

Bill

Java Resources at www.wbrogden.com
nikki sinha
Greenhorn

Joined: Jul 04, 2012
Posts: 14
William Brogden wrote:Exactly how does the IMG tag in the HTML written by the JSP refer to the image source?

Bill


i am a little confused about this... but what i did is using the url pattern of the servlet given in the web.xml


userimage is my servlet
if i am wrong then please correct me
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12683
    
    5
Whatever image you tried to paste into your post is not showing in my browser. It is much more useful to cut and paste the actual text from web.xml - kindly use the "code" tags.

Also kindly show the exact URL as you have formulated it in the HTML written by your JSP - use your browser's "view source" capability to get the exact text.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display image from bytearray
 
Similar Threads
Image Resizing Help
Convert Base64 String to JPG Without Quality Loss
Converting a Base64 encoded String to an Image
java.lang.IllegalArgumentException: im == null!
problem encoding and decoding base64