How to read JPeg images in Java

As part of our series of Handling common image file formats in Java I will be writing about how we can read JPeg images in Java where I mention the different libraries that enable us to read JPeg images.

What is JPeg?

JPEG (Joint Photographic Experts Group) is a file type of images with the extensions .jpg and .jpeg.

It is commonly used for digital images as it gives you high quality images. One main feature of JPeg is that it enables you to choose between quality and file size; you can sacrifice quality for a smaller file or vice versa.

There are many libraries out there that can read JPeg images. These include ImageIO, JAI and JDeli.

How to read JPeg images in Java?

Here are some code examples using Image IO, JAI and JDeli to read JPEG.

ImageIO:

File jpegFile = new File("jpegImage.jpg");
BufferedImage image = ImageIO.read(jpegFile);

You can find the javadocs for ImageIO here. You can find more information on ImageIO (included with the JDK) on their main page.

JAI:

 RenderedImage image = JAI.create("fileload", "test1.jpeg");

You can find the javadocs for JAI here. More information on JAI can be found here.

JDeli:

JpegDecoder decoder = new JpegDecoder();
BufferedImage image = decoder.read(rawImageBytes);

You can find the javadocs for JDeli here. If JDeli interests you, you can find more information here.

We have also created a useful how to series on how to read and write various Image formats. You can find moire about this on our Index.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

Related Posts:

The following two tabs change content below.
A Java developer at IDRSolutions with 4 years of experience in Java (self-taught). Now looking forward to speaking at Java One. A knowledge seeker who likes to try out and explore new things.
Zain

About Zain

A Java developer at IDRSolutions with 4 years of experience in Java (self-taught). Now looking forward to speaking at Java One. A knowledge seeker who likes to try out and explore new things.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>