Extract Image Information - Windows C DLL

This tutorial shows how to get information about an image file using the LEADTOOLS L_FileInfo function in a Windows C/C++ API application.

Overview  
Summary This tutorial covers how to obtain information from image files using the LEADTOOLS SDK in a Windows CDLL application.
Completion Time 30 minutes
Visual Studio Project Download tutorial project (18 KB)
Platform Windows C DLL Application
IDE Visual Studio 2017, 2019
Development License Download LEADTOOLS
Try it in another language

Required Knowledge

Get familiar with the basic steps of creating a project and loading/displaying an image by reviewing the Add References and Set a License and Load, Display, and Save Images tutorials, before working on the Extract Image Information - Windows C DLL tutorial.

Create the Project and Add LEADTOOLS References

Start with a copy of the project created in the Load, Display, and Save Images tutorial. If the project is not available, create it by following the steps in that tutorial.

Open the pre-compiled header file (either pch.h or stdafx.h, depending on the version of Visual Studio used) and ensure the below lines are added.

#define LTV22_CONFIG  
#include "C:\LEADTOOLS22\Include\L_Bitmap.h" // use the actual path where LEADTOOLS is installed  
 
#pragma comment (lib, "C:\\LEADTOOLS22\\Lib\\CDLL\\x64\\Ltkrn_x.lib")  
#pragma comment (lib, "C:\\LEADTOOLS22\\Lib\\CDLL\\x64\\Ltfil_x.lib") // file loading and saving  
#pragma comment (lib, "C:\\LEADTOOLS22\\Lib\\CDLL\\x64\\Ltdis_x.lib") // image display 

Note

For a complete list of DLLs that are required for specific application features, refer to Files to be Included with your Application - C API.

Set the License File

The License unlocks the features needed for the project. It must be set before any toolkit functionality 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.

Add the Get Image Information Code

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

In the Solution Explorer, double-click the resources file (.rc).

Add a new &Image Info menu item to the File drop-down menu, between the Open and Save items. Leave the new menu item's ID as ID_FILE_IMAGEINFO.

Open the project's CPP file and navigate to the WndProc function. Under the switch (wmId) statement that is below the WM_COMMAND case, add a new case and the code below.

switch (wmId) 
{ 
   case ID_FILE_IMAGEINFO: 
   { 
      TCHAR szFileName[260] = TEXT(""); // File name 
      if (SUCCESS != GetBitmapLoadingName(hWnd, szFileName, ARRAYSIZE(szFileName))) 
         break; 
      FILEINFO info = { 0 }; // Make sure to fill the struct with zeros before using it 
      if (SUCCESS != L_FileInfo(szFileName, &info, sizeof FILEINFO, FILEINFO_TOTALPAGES, NULL)) 
      { 
         MessageBox(hWnd, TEXT("Error getting file information"), TEXT("LEADTOOLS Demo"), MB_ICONERROR); 
         break; 
      } 
 
      L_TCHAR CONST* pszColorSpace[] = 
      { 
         L_TEXT("BGR"), 
         L_TEXT("YUV"), 
         L_TEXT("CMYK"), 
         L_TEXT("CIELAB") 
      }; 
      L_TCHAR CONST* pszByteOrder[] = 
      { 
         L_TEXT("RGB"), 
         L_TEXT("BGR"), 
         L_TEXT("GRAY"), 
         L_TEXT("<not used with info>"), 
         L_TEXT("<not used with info>"), 
         L_TEXT("ROMM"), 
         L_TEXT("<not used with info>"), 
         L_TEXT("RGB565") 
      }; 
 
      L_TCHAR CONST szFormatMessage[] = L_TEXT( 
         "Image Format: %d\n" 
         "Information for: %s\n" 
         "BitsPerPixel: %d\n" 
         "ColorSpace: %s\n" 
         "Byte Order: %s\n" 
         "Image Height: %d\n" 
         "Image Width: %d\n" 
         "Image X Resolution: %d\n" 
         "Image Y Resolution: %d\n" 
         "Compression: %s\n" 
         "Total Pages: %d"); 
      L_TCHAR szMessage[1024] = TEXT(""); 
      wsprintf(szMessage, szFormatMessage, 
         info.Format, 
         info.Name, 
         info.BitsPerPixel, 
         pszColorSpace[info.ColorSpace], 
         pszByteOrder[info.Order], 
         info.Width, 
         info.Height, 
         info.XResolution, 
         info.YResolution, 
         info.Compression, 
         info.TotalPages); 
      MessageBox(hWnd, szMessage, TEXT("File Information"), MB_ICONINFORMATION); 
   } 
   break; 
   // Keep rest of the code as is 

The code for the GetBitmapLoadingName() function, called inside the code above, is listed in the Load, Display, and Save Images tutorial.

Important Notes

  • There are more members inside the FILEINFO structure. The snippet above showcases some of the most commonly used file properties.
  • The FILEINFO structure must be filled with zeros before using it with L_FileInfo().

Run the Project

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

If the steps were followed correctly, the application should run. To test, follow the instructions below.

  1. Select File -> Image Info.

  2. Select the image you would like to gather information on and press OK.

    The application runs and a message displays the extracted information from the selected image file.

Wrap-up

This tutorial showed how to use the L_FileInfo function and FILEINFO structure to gather information from a selected image.

See Also

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

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.