How do I Read Image File?

Category: java.awt, viewed: 1899 time(s).

Here you see a code sample to read an image file. This code will work either the image file is located in a file folder or inside a jar file. You can use javax.imageio.ImageIO class to read the image file.

 
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
 
public class ReadingImage
{
    public void getImage()
    {
        try
        {
            BufferedImage image = 				 
                ImageIO.read(getClass().getResource("Sunset.jpg"));
 
            // Do something with the image.
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }
 
    public static void main(String[] args)
    {		
        ReadingImage ri = new ReadingImage();
        ri.getImage();
    }
}
 
 
Bookmark this example!  

Most Viewed Examples

Google

100 Top & Latest


eXTReMe Tracker
visitor stats