Extract Image Information - Java

This tutorial shows how to create a Java application that uses the CodecsImageInfo class to get information about the various image files supported by LEADTOOLS.

Summary This tutorial covers how to use the CodecsImageInfo Class in a Java application.
Completion Time 30 minutes
Eclipse Project Download tutorial project (2 KB)
Platform Java Application
IDE Eclipse
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

Get familiar with the basic steps of creating a project by reviewing the Add References and Set a License tutorial, before working on the Extract Image Information - Java tutorial.

Create the Project and Add the LEADTOOLS References

Start with a copy of the project created in the Add References and Set a License tutorial. If that project is unavailable, follow the steps in that tutorial to create it.

The references needed depend upon the purpose of the project. References can be added by local .jar files located at <INSTALL_DIR>\LEADTOOLS21\Bin\Java.

For this project, the following references are needed:

This tutorial uses LEADTOOLS Codec library support. For a complete list of which JAR files are required for your application, refer to Files to be Included with your Java Application

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit function is called. For details including tutorials for different platforms, refer to Setting a Runtime License.

There are two types of runtime licenses:


Adding LEADTOOLS references and setting a license are covered in more detail in the Add References and Set a License tutorial.

Add the Get Image Information Code

With the project created, the references added, and the license set, coding can begin.

Open the _Main.java class in the Project Explorer. Add the following statements to the import block at the top.

// import block at the top 
import java.io.IOException; 
import java.nio.file.*; 
import leadtools.*; 
import leadtools.codecs.*; 

Add a new method called RasterCodecsImageInfo("C:\\LEADTOOLS21\\Resources\\Images\\image1.cmp");. Call the new method below SetLicense(); inside the main() method, as shown below.

public static void main(String[] args) throws IOException { 

Add the below CodecsImageInfo code inside the new method. The method's parameter will be the file path to the image from which the information is to be gathered from. For this tutorial, this sample image will be used.

static void RasterCodecsImageInfo(String fileName) 
    RasterCodecs codecs = new RasterCodecs(); 
    CodecsImageInfo info = codecs.getInformation(fileName, true); 
    String inputFileName = fileName.substring(0, fileName.lastIndexOf(".")); 
    String codecsInfoString = ( 
        "Image Format: " + info.getFormat() + "\n" + 
        "Information for: " + inputFileName + "\n" + 
        "BitsPerPixel: " + info.getBitsPerPixel() + "\n" + 
        "BytesPerLine: " + info.getBytesPerLine() + "\n" + 
        "ColorSpace: " + info.getColorSpace() + "\n" + 
        "Byte Order: " + info.getOrder() + "\n" + 
        "Image Height: " + info.getHeight() + "\n" + 
        "Image Width: " + info.getWidth() + "\n" + 
        "Image X Resolution: " + info.getXResolution() + "\n" + 
        "Image Y Resolution: " + info.getYResolution() + "\n" + 
        "Compression: " + info.getCompression() + "\n" + 
        "Page Number: " + info.getPageNumber() + "\n" + 
        "Total Pages: " + info.getTotalPages() 


There are more properties inside the CodecsImageInfo class. The snippet above showcases the most commonly used properties.

Run the Project

Run the project by pressing Ctrl + F11, or by selecting Run -> Run.

If the steps were followed correctly, the application runs and the console displays the file's information.

The application runs and the console displays the extracted information


This tutorial showed how to use the CodecsImageInfo class.

See Also

Help Version 21.0.2021.5.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.