Extract Image Information - Console C#

This tutorial shows how to create a C# Windows Console 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 C# Windows Console application.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (2 KB)
Platform C# Windows Console Application
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS

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 - Console C# tutorial.

Create the Project and Add LEADTOOLS References

Create a new C# Windows Console project, and add the below necessary LEADTOOLS references.

If using NuGet references, this tutorial requires the following NuGet package:

If using local DLL references, add the following DLLs:

The local DLLs are located at <INSTALL_DIR>\LEADTOOLS 20\Bin\Dotnet4\x64

For a complete list of which Codec DLLs are required for specific formats, refer to Files to be Included in Your 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:

Note

Adding LEADTOOLS NuGet and local 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 Program.cs in the Solution Explorer. In the Program class, add a new method called RasterCodecsImageInfo(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.cmp");. Then 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. For this tutorial, this sample image will be used.

C#
// Using block at the top 
using System; 
using System.IO; 
using Leadtools; 
using Leadtools.Codecs; 
C#
RasterCodecsImageInfo(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.cmp"); 
C#
static void RasterCodecsImageInfo(string fileName) 
{ 
    using (RasterCodecs codecs = new RasterCodecs()) 
    { 
        CodecsImageInfo info = codecs.GetInformation(fileName, true); 
        string inputFileName = Path.GetFileNameWithoutExtension(fileName); 
        string codecsInfoString = ($"Image Format: {info.Format}\n" + 
                $"Information for: {inputFileName}\n" + 
                $"BitsPerPixel: {info.BitsPerPixel}\n" + 
                $"BytesPerLine: {info.BytesPerLine}\n" + 
                $"ColorSpace: {info.ColorSpace}\n" + 
                $"Byte Order: {info.Order}\n" + 
                $"Image Height: {info.Height}\n" + 
                $"Image Width: {info.Width}\n" + 
                $"Image X Resolution: {info.XResolution}\n" + 
                $"Image Y Resolution: {info.YResolution}\n" + 
                $"Compression: {info.Compression}\n" + 
                $"Page Number: {info.PageNumber}\n" + 
                $"Total Pages: {info.TotalPages}"); 
 
        Console.WriteLine(codecsInfoString); 
        Console.ReadLine(); 
    } 
} 

Note

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

Because the RasterCodecs class implements IDisposable, make sure it is in a using statement for proper disposal.

Run the Project

Run the project by pressing F5 or by selecting Debug -> Start Debugging.

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

Wrap-up

This tutorial showed how to use the CodecsImageInfo class.

See Also

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