L_SaveBitmapMemory

#include "l_bitmap.h"

L_LTFIL_API L_INT L_SaveBitmapMemory(phHandle, pBitmap, nFormat, nBitsPerPixel, nQFactor, puSize, pSaveOptions)

L_HGLOBAL* phHandle;

address of the memory handle

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

L_SIZE_T* puSize;

address of a file-size variable to be updated

pSAVEFILEOPTION pSaveOptions;

pointer to optional extended save options

Saves a bitmap to a file in memory. The output can be in any of the supported compressed or uncompressed file formats.

Parameter

Description

phHandle

Pointer to the memory handle that will be updated with a new memory handle that contains the saved image. To append a page to an existing image, this pointer should point to a valid memory handle (phHandle!=NULL). If you have no image saved in memory, this pointer should point to NULL (phHandle=NULL).

If you pass a valid memory handle, the old handle will become invalid and a new handle created. The new handle may have the same value as the old handle, however, this is not guaranteed.

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.

puSize

Address of a variable, which the function updates to give you the size of the file.

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

To use this function, do the following:

1.

Declare a memory handle. You can then pass its address in this function, which will allocate the memory, save the bitmap, and unlock the memory. Set the value of the HANDLE to NULL.

2.

Declare a long integer (L_UINT32) variable for the file-size. You can then pass its address in this function, which will update its value with the size of the file.

3.

Call this function to save the bitmap in the specified memory handle.

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

This function cannot be used in combination with L_RedirectIO.

Note:

More options are available in the SAVEFILEOPTION structure. However, please note that the PageNumber data member of the SAVEFILEOPTION structure is not valid with this function. Therefore you cannot save a multi-page file with this function.

Note:

Redirected IO is not supported for some file formats.  For more information, refer to File Formats for Which Redirected IO is Not Supported.

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 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_SetComment, 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: 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 SAVEMEM example. This example loads a temporary bitmap, saves it as a file in memory, then loads the memory-resident file into a new bitmap handle.

L_INT SaveBitmapMemoryExample(L_VOID) 
{ 
   L_INT nRet; 
   BITMAPHANDLE LeadBitmap;   /* Bitmap handle for the final image */ 
   BITMAPHANDLE TmpBitmap;    /* Bitmap handle for the initial image */ 
   HGLOBAL hFileInMemory = NULL;     /* Memory handle */ 
   L_SIZE_T uMemSize;   /* Size of the data in memory */ 
   L_UCHAR  *pData;     /* Pointer to the data in memory */ 
 
   /* 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 CMP file in memory */ 
   nRet = L_SaveBitmapMemory(&hFileInMemory, &TmpBitmap, FILE_CMP, 24, QS, &uMemSize, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Free the temporary bitmap */ 
   if(TmpBitmap.Flags.Allocated)   
      L_FreeBitmap(&TmpBitmap); 
 
   /* Get the pointer to the memory-resident file */ 
   pData = (L_UCHAR  *) GlobalLock (hFileInMemory); 
 
   /* Load the new bitmap from memory at its own bits per pixel  */ 
   nRet = L_LoadBitmapMemory (pData, &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, uMemSize, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
 
   /* Clean up */ 
   GlobalUnlock (hFileInMemory); 
   GlobalFree (hFileInMemory); 
   L_FreeBitmap(&LeadBitmap); 
   return SUCCESS; 
} 

Help Version 20.0.2018.1.19
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help