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 |
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 a new C# Windows Console project, and add the below necessary LEADTOOLS references.
If using NuGet references, this tutorial requires the following NuGet package:
Leadtools.Formats.Raster.Common
If using local DLL references, add the following DLLs:
The local DLLs are located at <INSTALL_DIR>\LEADTOOLS 20\Bin\Dotnet4\x64
Leadtools.dll
Leadtools.Codecs.dll
Leadtools.Codecs.Cmp.dll
For a complete list of which Codec DLLs are required for specific formats, refer to Files to be Included in Your 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 NuGet and local 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 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.
// Using block at the top
using System;
using System.IO;
using Leadtools;
using Leadtools.Codecs;
RasterCodecsImageInfo(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.cmp");
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 implementsIDisposable
, make sure it is in ausing
statement for proper disposal.
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.
This tutorial showed how to use the CodecsImageInfo
class.