Reading an Image from a File, InputStream, or URL
This example demonstrates how to use the javax.imageio package to
read an image from a file, input stream, or URL. The example also
demonstrates how to display the image on the screen.
GIF, PNG, and JPEG formats are supported by the
javax.imageio package by default.
This example works only in J2SE 1.4. For a method that works
since J2SE 1.3, see Reading an Image or Icon from a File.
Image image = null;
try {
// Read from a file
File file = new File("image.gif");
image = ImageIO.read(file);
// Read from an input stream
InputStream is = new BufferedInputStream(
new FileInputStream("image.gif"));
image = ImageIO.read(is);
// Read from a URL
URL url = new URL("http://hostname.com/image.gif");
image = ImageIO.read(url);
} catch (IOException e) {
}
// Use a label to display the image
JFrame frame = new JFrame();
JLabel label = new JLabel(new ImageIcon(image));
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
thanx a lot it really helped me
thanx... would you by any chance help me to make the image resize according to the size of the frame?
new FileInputStream("image.gif")); results in FileNotFound exception. Help?
To the poster on Jul 12, image.gif needs to be located in your root directory. Otherwise just specify path to the image: new FileInputStream("/images/navigation/back.gif")); or whatever the path is relative to your root directory.
Hi everyone. I'm wondering how can I load an image from any directory of the disc, not from the root of the project. I'm working whit JDeveloper 11.1.1.2.0. With the image component work only if the image is in the root. Thanks in advance, any help will be fine.
Is it possible to parse an image which contains text content and retrieve the text contenet separately ? In otherwords suppose I have a scanned copy of my typed assignment.can i get the text content from the scanned image ?
It is a really useful web site for me , thanks.
Just what I was looking for. :)
Thanks man! It's very interesting shit!
Thanks a lot!
Hi Friends I am writing an image to the jsp page using
OutputStream os = response.getOutputStream();
ImageIO.write(image, "jpeg", os);
Where image is my buffered image, i am getting "javax.imageio.IIOException: Maximum supported image dimension is 65500 pixels" error.
Is there a way to fix this with out changing the actual image dimensions ?
Can i read DWF file with this ImageIO.read() function
Hi Very interesting to me this code portion, I have a question, sorry my basic knowledge are, what is the sustancial difference between "new File()" and "new FileInputStream()".
Regards.
how to retrieve the multiple images from mysql database in swing
that's great!
Thanks for post and comment there are great @@
Please help. How to set cookies for imaging?
this is very nice!
this is very nice!
nice
this is very nice!
this is very nice!
this is very nice!
God I love this site: all the examples are so simple - exactly what I want.
Amazing work, THAAAAAAAAAAAANKS
Thank you :) this is very nice.