LBitmapBase::Save

Summary

Saves the class object's bitmap image to a file in any of the supported compressed or uncompressed formats.

Syntax

#include "ltwrappr.h"

virtual L_INT LBitmapBase::Save(nFormat, nBitsPerPixel, nQFactor, uFlags, pSaveFileOption=NULL)

virtual L_INT LBitmapBase::Save(pszFile, nFormat, nBitsPerPixel, nQFactor, nPageNumber, uFlags)

virtual L_INT LBitmapBase::Save(pszFile, nFormat, nBitsPerPixel, nQFactor, uFlags, pSaveFileOption=NULL)

virtual L_INT LBitmapBase::Save(nFormat, nBitsPerPixel, nQFactor, nPageNumber, uFlags)

Parameters

L_TCHAR * pszFile

Character string containing the output file name.

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_INT nPageNumber

Represents a page number in a multipage file. This parameter is used only if the uFlags parameter is MULTIPAGE_OPERATION_REPLACE or MULTIPAGE_OPERATION_INSERT. If uFlag is MULTIPAGE_OPERATION_REPLACE, nPageNumber represents the number of the page to replace (the first page is page 1). If uFlags is MULTIPAGE_OPERATION_INSERT, nPageNumber represents the number of the page in front of which the new page will be inserted. For example, if nPageNumber is 1 and uFlags is MULTIPAGE_OPERATION_INSERT, then the page you save will become the first page in the file.

L_UINT uFlags

Flag that indicates how to save a new page in a multipage file that supports insert and replace operations. Possible values are:

Value Meaning
MULTIPAGE_OPERATION_OVERWRITE [1] No insert/replace/append is performed. An existing file is overwritten. This is comparable to bMultipage being FALSE in earlier versions.
MULTIPAGE_OPERATION_APPEND [2] or [-1] The page is appended if the file exists.
MULTIPAGE_OPERATION_REPLACE [3] Replace the page specified in the nPage.
MULTIPAGE_OPERATION_INSERT [4] Insert the new page before the page specified in the nPage.

pSAVEFILEOPTION pSaveFileOption

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

The image will be saved to the file specified by the last call to LBitmapBase::SetFileName or to the file last loaded by LBitmapBase::Load.

If the bitmap is 8 bits per pixel or greater, use the LEAD CMP format or one of the JPEG (JTIF or JFIF) formats to save disk space.

NOTE: 4:1:1 and 4:2:2 formats use subsampling for the color components. In the case of 4:1:1, the color components for 4 pixels are averaged during compression. This will cause a color shift, but the shift is tolerable for low compression ratios. If you have high compression and repeated savings, then the color shift will increase. Due to this characteristic of the JPEG algorithm, the only ways to avoid this are to: (a) use 4:4:4 (which has no subsampling), or (b) avoid repeated load and resave.

If the bitmap is 1-bit per pixel, use the LEAD 1-bit format or a CCITT Group 3 or 4 format to save disk space.

For CCITT Group 3 and 4 formats, the first RGBQUAD structure in the bitmap handle's hPalette field determines the white component of the image. If the rgbRed field is 0, then all 0 bits in the image are assumed to be black. Otherwise, all zero (0) bits in the image are assumed white.

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

The following file formats support append operations:

The following file formats support replace operations:

The following file formats support insert operations:

This function does not support signed data images, unless they are DICOM images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image that is not a DICOM image is passed to this function.

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 LBitmapBase::SetDitheringMethod as illustrated below:

// 'leadBitmap' is a colored LBitmapBase 
// 'leadFile' is LFile object 
// Setup FloydStein dithering: 
leadBitmap.SetDitheringMethod(FLOYD_STEIN_DITHERING); 
SAVEFILEOPTION saveOptions = {0}; 
leadFile.GetDefaultSaveFileOption(&saveOptions, sizeof(SAVEFILEOPTION)); 
saveOptions.Flags |= ESO_USEDITHERINGMETHOD; 
leadFile.Save(FILE_CCITT_GROUP4, 1, 0, 0, &saveOptions); 
// or any other Save overloads or methods 

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

For an example, refer to LBitmapBase::Load.

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

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.