imageio

Read image from file

Photo of Ilias TsagklisIlias TsagklisNovember 11th, 2012Last Updated: May 9th, 2013
1 189 1 minute read

In this tutorial we are going to see how to read an image from a file. This is very useful when you want to store image files in your system and you want to use them to enrich the graphics of your application.

In order to read image from a file:

  • You have to open a newFile in the image file.
  • UseImageIO.read(file) to get an Image object.

 
 
 
Let’s see the code snippet that follows:

package com.javacodegeeks.snippets.desktop;import java.awt.Image;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;public class ReadImageFromFile {public static void main(String[] args) throws IOException {// input image fileFile file = new File("myimage.jpg");Image image = ImageIO.read(file);int width = image.getWidth(null);int height = image.getHeight(null);}}

 
This was an example on how to read image from a file.

Do you want to know how to develop your skillset to become aJava Rockstar?
Subscribe to our newsletter to start Rockingright now!
To get you started we give you our best selling eBooks forFREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to theTerms andPrivacy Policy

Thank you!

We will contact you soon.

Photo of Ilias TsagklisIlias TsagklisNovember 11th, 2012Last Updated: May 9th, 2013
1 189 1 minute read
Photo of Ilias Tsagklis

Ilias Tsagklis

Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor atJava Code Geeks.

Related Articles

Subscribe
Notify of
guest
I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.

I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.