File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Fetching an image from the specified URL and resizing it. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Fetching an image from the specified URL and resizing it." Watch "Fetching an image from the specified URL and resizing it." New topic
Author

Fetching an image from the specified URL and resizing it.

Debasmita Dash
Greenhorn

Joined: Apr 07, 2009
Posts: 19
Hi All,

I have to fetch an image from the given URL and resize it before displaying the same on the html page.
I am able to do this using java.awt.image.BufferedImage and javax.imageio.ImageIO APIs. But I need to do the same without using java.awt. I tried the following code but it's not working. The output file doesn't contain the image.


Thanks for your help.
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 130

Did you mean "D:\\output.gif" ?

Also, read() is not guaranteed to read a full buffer's worth.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

And what is the purpose of writing to a ByteArrayOutputStream and then copying from that to a FileOutputStream? Why not just write directly to the FileOutputStream? (With the corrected code as per Carey Brown's comment, of course.)
Debasmita Dash
Greenhorn

Joined: Apr 07, 2009
Posts: 19
Thanks Carey and Paul for replying.

I will be using the ByteArrayOutputStream further to display the image in html page and have used the FileOutputStream here to check the image content.

Thanks,
Debasmita
 
 
subject: Fetching an image from the specified URL and resizing it.
 
Threads others viewed
Encoding/decoding problem
Get byte[] of image
ImageIO.read() timeout?
java.io.IOException at out.write()
Null check on an image
IntelliJ Java IDE