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 Formats of Output Files. 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 file to FILE_CMP, FILE_JPEG, FILE_JPEG_411, FILE_JPEG_422, FILE_TIF_JPEG, FILE_LEAD1JTIF, FILE_LEAD2JTIF, FILE_FPX_JPEG_QFACTOR, FILE_EXIF_JPEG, and FILE_PNG. 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 is 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/Medical Imaging editions .

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.

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

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

Windows 2000 / XP/Vista, Windows CE.

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 (TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\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(TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\TEST.BMP"), &TmpBitmap, FILE_BMP, 24, 0, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* Free the temporary bitmap */
   if(TmpBitmap.Flags.Allocated)
      L_FreeBitmap(&TmpBitmap);
   return SUCCESS;
}