L_SaveFile

#include "l_bitmap.h"

L_LTFIL_API L_INT L_SaveFile(pszFile, pBitmap, nFormat, nBitsPerPixel, nQFactor, uFlags, pfnCallback, pUserData, pSaveOptions)

Creates a file in any of the supported compressed or uncompressed formats, using input data that your callback function supplies.

Parameters

L_TCHAR* pszFile

Character string containing the name of the image file to save.

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle that describes the data to be saved. The bitmap handle can contain the actual data, but does not have to, since your callback function can supply the data.

However, the bitmap handle must contain values for the following fields: Width, Height, BitsPerPixel, BytesPerLine, nColors, ViewPerspective, Order, and DitheringMethod. (The BytesPerLine value must be a multiple of four.)

L_INT nFormat

Output file format. For valid values, refer to Files To Be Included With Your Application.

L_INT nBitsPerPixel

Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Files To Be Included With Your Application. If nBitsPerPixel 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.

L_UINT uFlags

Binary flags that determine the behavior of L_SaveFile. You can specify one of the following values:

Value Meaning
SAVEFILE_FIXEDPALETTE [0x0001] The function uses the fixed palette for images that are saved as 8 bits per pixel or less.
SAVEFILE_OPTIMIZEDPALETTE [0x0002] The function uses the individual image's optimized palette for images that are saved as 8 bits per pixel or less. The optimized palette must be included in the bitmap handle.
SAVEFILE_MULTIPAGE [0x0004] The function saves the image in a multipage file. It appends the image as the last one in the file. You can save multipage images in PCX, GIF, and most TIFF file formats (including JTIF, but excluding EXIF).
SAVEFILE_GRAYOUTPUT [0x0008] The function saves the image as grayscale.

FILESAVECALLBACK pfnCallback

Optional callback function for additional processing.

If you do not provide a callback function, use NULL as the value of this parameter.

If you do provide a callback function, use the function pointer as the value of this parameter.

The callback function must adhere to the syntax described in FILESAVECALLBACK Function.

L_VOID* pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID  *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure. If the additional parameters are not needed, you can pass NULL in this parameter.

pSAVEFILEOPTION pSaveOptions

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

Returns

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

Comments

If you provide a callback function, it must supply the image data. It can also do other useful things, such as updating a status bar.

If you do not provide a callback function, this function saves data from the specified bitmap.

If you use a callback and save the bitmap as a MacPaint (MAC) file, the image to be saved must have a width of 576 and a height of 720 (the required dimensions of that format).

Support for 12- and 16-bit grayscale images is only available in the Document and Medical Imaging toolkits.

Notes:

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

For information on saving bitmaps that have been window leveled, refer to Saving Window-Leveled Bitmaps.

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 the recommended when converting colored images containing text for document processing such as OCR and Barcode. The result text will 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 
// Set up FloydStein dithering: 
bitmapHandle.DitheringMethod = FLOYD_STEIN_DITHERING; 
SAVEFILEOPTION saveOptions = {0}; 
L_GetDefaultSaveFileOption(&saveOptions, sizeof(SAVEFILEOPTION)); 
saveOptions.Flags |= ESO_USEDITHERINGMETHOD; 
// 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 function such as: 
// L_SaveFile(fileName, &bitmapHandle, FILE_CCITT_GROUP4, 1, 0, 0, NULL, NULL, &saveOptions) 

NITF files contain both raster and non-raster data and so NITF files cannot be saved using the standard raster library. Use the separate NITF library to create and save NITF files.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

For complete sample code, refer to the SAVECB example. This example uses L_SaveFile with a callback function that supplies the image data. Refer to the FILESAVECALLBACK function to see how the callback function supplies the image data.

L_INT EXT_CALLBACK SaveImageCB (pBITMAPHANDLE pBitmap, 
                                L_UCHAR     * pBuffer, 
                                L_UINT        nRowBegin, 
                                L_UINT        nRowsToGet, 
                                L_VOID       * pUserData); 
 
L_INT SaveFileExample(HINSTANCE hInst,   /* Current instance of the application, set by the InitInstance function */ 
                      pBITMAPHANDLE LeadBitmap) 
{ 
   L_INT nRet;            /* Return value                     */ 
   L_TCHAR szMessage[80]; /* Buffer for the MessageBox string */ 
 
   UNREFERENCED_PARAMETER(hInst); 
 
 
   /* Set the dithering method for the save */ 
   LeadBitmap->DitheringMethod = FLOYD_STEIN_DITHERING; 
 
   /* Save the file as an 8-bit Windows BMP file with a fixed palette */ 
   /* Set the callback function for the L_SaveFile function.*/ 
   nRet = L_SaveFile(MAKE_IMAGE_PATH(TEXT("TEST2.BMP")),  
                     LeadBitmap, 
                     FILE_BMP, 8, 0,  
                     SAVEFILE_FIXEDPALETTE, 
                     SaveImageCB, 
                     NULL, 
                     NULL); 
 
   /* Notify the user with a message box */ 
   if (nRet == SUCCESS) 
   { 
      MessageBox (NULL, TEXT("File was saved"), TEXT("Notice"), MB_OK); 
   } 
   else 
   { 
      wsprintf (szMessage, TEXT("Error %d saving the file"), nRet); 
      MessageBox (NULL, szMessage, TEXT("Error"), MB_OK); 
      return nRet; 
   } 
   return SUCCESS; 
} 

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

LEADTOOLS Raster Imaging C API Help