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.
Overview | |
---|---|
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 |
|
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.
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>\LEADTOOLS23\Bin\Java
.
For this project, the following references are needed:
leadtools.jar
leadtools.codecs.jar
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
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:
Note: Adding LEADTOOLS references and setting a license are covered in more detail in the Add References and Set a License tutorial.
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 java.io.IOException;
import java.nio.file.*;
import leadtools.*;
import leadtools.codecs.*;
Add a new method called RasterCodecsImageInfo(String fileName)
. Call the new method below SetLicense();
inside the run()
method, as shown below.
private void run(String[] args) {
try {
Platform.setLibPath("C:\\LEADTOOLS23\\Bin\\CDLL\\x64");
Platform.loadLibrary(LTLibrary.LEADTOOLS);
Platform.loadLibrary(LTLibrary.CODECS);
SetLicense();
String fileName = "C:\\LEADTOOLS23\\Resources\\Images\\image1.cmp";
RasterCodecsImageInfo(fileName);
} catch (Exception ex) {
System.err.println(ex.getMessage());
ex.printStackTrace();
}
}
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.
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());
System.out.println(codecsInfoString);
codecs.dispose();
}
Note: There are more properties inside the
CodecsImageInfo
class. The snippet above showcases the most commonly used properties.
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.
This tutorial showed how to use the CodecsImageInfo
class.