Saves a list of bitmaps in a multipage file.


#include "l_bitmap.h"

L_LTFIL_API L_INT L_SaveBitmapList(lpszFile, hList, nFormat, nBits, nQFactor, pSaveOptions)


L_TCHAR* lpszFile

Character string containing the output file name.


Handle to the list of bitmaps.

L_INT nFormat

Output file format. You can save multipage images in PCX, GIF, and most TIFF file formats (including JTIF, but excluding EXIF). For possible values, refer to Formats of Output Files.

Single image formats are also valid (although only one image can be stored).

L_INT nBits

Resulting file's pixel depth. For possible values, refer to Formats of Output Files. If nBits is 0, the file will be stored using the closet BitsPerPixel value supported by that format. For example, if a file format supports 1, 4, and 24 BitsPerPixel, and the pBitmap->BitsPerPixel is 5, the file will be stored as 24 bit. Likewise, if the pBitmap->BitsPerPixel is 2, the file will be stored as 4 bit.

L_INT nQFactor

This parameter is used when saving an image to file format that supports quality factor (QFactor). QFactor is a number that determines the degree of loss in the compression process.

For possible values, refer to Compression Quality Factors.


Pointer to optional extended save options. Pass NULL to use the default save options.


Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.


Single-image formats are also valid for output, but only the first image in the list is saved.

Note: More options are available in the SAVEFILEOPTION structure.

This function supports signed data images, but only DICOM and TIFF formats support signed data. This function will return an error code if you attempt to save a signed image to a format other than DICOM or TIFF.

If the bitmap has a region, the region stored in the bitmap will be saved (if the image is saved as one of the TIFF file formats).

You can convert one file format to another when you save a file. You can also use the high-level function, L_FileConvert, to convert any possible format to any other possible format.

In LEADTOOLS version 17 and up, when saving a colored image (such as a 24-bits per pixel image) to bitonal (1-bit per pixel), the toolkit will not use any dithering when converting the image data. This is done because dithering is not recommended when converting colored images containing text for document processing such as OCR and Barcode. Dithering causes the resulting text to be fuzzy and hard for a recognition engine to process. To save a colored image as bitonal with Floyd-Stein dithering (the behavior of LEADTOOLS 16.5 and earlier), use the ESO_USEDITHERINGMETHOD along with BITMAPHANDLE.DitheringMethod as illustrated below:

// 'pBitmap' is a colored BITMAPHANDLE 
// Setup FloydStein dithering: 
bitmapHandle.DitheringMethod = FLOYD_STEIN_DITHERING; 
SAVEFILEOPTION saveOptions = {0}; 
L_GetDefaultSaveFileOption(&saveOptions, sizeof(SAVEFILEOPTION)); 
// Save the bitmap as 1-bpp with auto-dithering: 
L_SaveBitmap(fileName, &bitmapHandle, FILE_CCITT_GROUP4, 1, 0, &saveOptions); 
// or any other L_SaveBitmapXyz or L_SaveFileXyz functions such as: 
// L_SaveFile(fileName, &bitmapHandle, FILE_CCITT_GROUP4, 1, 0, 0, NULL, NULL, &saveOptions) 

Required DLLs and Libraries


Win32, x64, Linux.

See Also




For complete sample code, refer to the CHILD.C module of the DEMO
This example saves a list of 8-bit bitmaps as an animated GIF file.

L_INT SaveBitmapListExample(HBITMAPLIST hList, 
                                            pBITMAPHANDLE LeadBitmap ) 
   L_INT nRet; 
   BITMAPHANDLE TmpBitmap; /* Temporary bitmap handle  */ 
   SAVEFILEOPTION SaveFileOption; /* File options when saving */ 
   /* Get a copy of the first image's bitmap handle */ 
   nRet = L_GetBitmapListItem(hList, 0, &TmpBitmap, sizeof(BITMAPHANDLE)); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Get the default SAVEFILEOPTION values */ 
   nRet = L_GetDefaultSaveFileOption(&SaveFileOption, sizeof(SAVEFILEOPTION)); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Use the target bitmap's palette as the global palette */ 
   nRet = L_GetBitmapColors(LeadBitmap, 0, 256, SaveFileOption.GlobalPalette); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Assign the other SAVEFILEOPTION fields */ 
   SaveFileOption.GlobalWidth = TmpBitmap.Width; 
   SaveFileOption.GlobalHeight = TmpBitmap.Height; 
   SaveFileOption.GlobalLoop = 0; 
   SaveFileOption.GlobalBackground = LeadBitmap->Background; 
   /* Save the bitmap list as an animated GIF file */ 
   nRet = L_SaveBitmapList(MAKE_IMAGE_PATH(TEXT("testan.gif")), hList, FILE_GIF, 8, 0, &SaveFileOption); 
   if(nRet != SUCCESS) 
      return nRet; 
   return SUCCESS; 

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

LEADTOOLS Raster Imaging C API Help

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