Splitting a Multi-page TIFF File

The following steps show how to loop through all pages of a multi-page TIFF file and extract each page, process it individually, and save it into a separate file.


Declare the following variables:

BITMAPHANDLE LeadBitmap = {0};  // LEAD bitmap 
FILEINFO FileInfo = {0};   // File info 
L_INT PageNumber, TotalPages;   // Page numbers 
LOADFILEOPTION LoadFileOption = {0};  // Loading options 
char szOutFileName[MAX_PATH];  // Output file name 


Determine the number of pages in the file:

L_FileInfo("MultiPage.tif", &FileInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL);
TotalPages = FileInfo.TotalPages;


Loop through the pages of the file; performing specific processing on each page, then save each page to a separate file:

L_GetDefaultLoadFileOption(&LoadFileOption, sizeof(LOADFILEOPTION)); 
for (PageNumber=1; PageNumber<=TotalPages; ++PageNumber) 
   // Load the next image in the loop 
   LoadFileOption.PageNumber = PageNumber; 
   L_LoadBitmap("MultiPage.tif", &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, &LoadFileOption, NULL); 
   // Check that it is properly loaded and allocated 
      // Perform specific processing on the page, such as flipping it 
      // Save the page to a separate file 
      wsprintf(szOutFileName, "PageNumber%4.4d.tif", PageNumber); 
      L_SaveBitmap(szOutFileName, &LeadBitmap, FILE_TIFLZW, LeadBitmap.BitsPerPixel, 0, NULL); 
      // Free the image from memory 
   } //if Allocated 
} //for loop 
Help Version 20.0.2019.9.22
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help