L_SaveBitmap - Raster Imaging C API Help

L_SaveBitmap

#include "l_bitmap.h"

L_LTFIL_API L_INT L_SaveBitmap(pszFile, pBitmap, nFormat, nBitsPerPixel, nQFactor, pSaveOptions)

L_TCHAR* pszFile;

output file name

pBITMAPHANDLE pBitmap;

pointer to the bitmap handle

L_INT nFormat;

output file format

L_INT nBitsPerPixel;

resulting file's pixel depth

L_INT nQFactor;

quality factor

pSAVEFILEOPTION pSaveOptions;

pointer to optional extended save options

Saves an image contained in a bitmap to a file in any of the supported compressed or uncompressed formats.

Parameter

Description

pszFile

Character string containing the output file name.

pBitmap

Pointer to the bitmap handle referencing the bitmap that holds the image data.

nFormat

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

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.

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.

pSaveOptions

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

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

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

NOTE: JFIF  4:1:1 and 4:2:2 formats use subsampling for the color components. In the case of 411, 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 inherent limitations of the JPEG algorithm, the only ways to avoid this are: (a) avoid repeated load and resave, or (b) use 4:4:4  format, which has no subsampling.

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 and Medical Imaging toolkits.

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 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.

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

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 
// Setup 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 functions such as: 
// L_SaveFile(fileName, &bitmapHandle, FILE_CCITT_GROUP4, 1, 0, 0, NULL, NULL, &saveOptions) 

Required DLLs and Libraries

LTFIL
File format DLLs

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64, Linux.

See Also

Functions:

L_SaveFile, L_SaveFileOffset, L_SaveFile, L_FileConvert, L_SetComment, L_DlgSave, L_SaveFileMemory

Topics:

Raster Image Functions: Saving Files

 

Raster Image Functions: Maintaining File Comments and Tags

 

Raster Image Functions: Low-Level Compression Functions

 

Raster Image Functions: Loading and Saving Stamp Images

 

Raster Image Functions: Redirecting Input and Output

 

Raster Image Functions: Input and Output

 

Loading and Saving Images

 

Saving a Region

For a list of functions that utilize the LOADFILEOPTION or SAVEFILEOPTION structures, refer to Functions Utilizing the LOADFILEOPTION or SAVEFILEOPTION structures.

Example

For complete sample code, refer to the DRAW example. This example loads a temporary bitmap and saves it to a new file

L_INT SaveBitmapExample(L_VOID) 
{ 
   L_INT nRet; 
   /* Bitmap handle for the temporary bitmap */ 
   BITMAPHANDLE TmpBitmap; 
 
   /* Load a bitmap at its own bits per pixel  */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Save the image as a 24-bit Windows BMP file */ 
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\out_Image3.cmp")), &TmpBitmap, FILE_BMP, 24, 0, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Free the temporary bitmap */ 
   if(TmpBitmap.Flags.Allocated) 
      L_FreeBitmap(&TmpBitmap); 
   return SUCCESS; 
} 

Help Version 20.0.2018.7.30
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help