virtual L_INT LMemoryFile::SaveBitmapBuffer(pLBuffer, puFileSize, nFormat, nBitsPerPixel, nQFactor, pSaveOptions)
Saves the class object's associated bitmap into an LBuffer object. The size of the LBuffer object's buffer must be specified by the user. The output can be in any of the supported compressed or uncompressed file formats.
Pointer to an LBuffer object into which the bitmap will be saved. Note that if this object's buffer is not large enough to accommodate the file in memory, the LMemoryFile::SaveBitmapBufferCallBack is called to allow the user to reallocate the buffer.
Pointer to a variable that will contain the size of the file in memory. This is not the final size of the LBuffer buffer, which may be larger than the memory file.
Output file format. For valid values, refer to Files To Be Included With Your Application.
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 closest BitsPerPixel value supported by that format. For example, if a file format supports 1, 4, and 24 BitsPerPixel, and LBitmapBase::GetBitsPerPixel gets the value 5, the file will be stored as 24 bit. Likewise, if LBitmapBase::GetBitsPerPixel gets the value 2, the file will be stored as 4 bit.
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.
Pointer to optional extended save options. Pass NULL to use the default save options.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
LMemoryFile::SaveBitmapBuffer saves a class object's associated bitmap into an LBuffer object. The output can be in any of the supported, compressed or uncompressed file formats. This function is similar to LMemoryFile::SaveBitmap, except the user is responsible for allocating/reallocating buffers. If the buffer of the LBuffer object is not large enough to accommodate the file in memory, the LMemoryFile::SaveBitmapBufferCallBack is called so the user can re-allocate the buffer. This callback function must be enabled by calling LBase::EnableCallBack.
If the user wants to allocate a buffer that is large enough to hold the file in memory, an upper bound on the file size can be estimated by the following formula:
RequiredBytes = (Image Width) * (Image Height) * (BitsPerPixel) / 8
Note that this is an estimate that does not include the size of the file header, and it does not take into account any compression. It is best to use a LMemoryFile::SaveBitmapBufferCallBack so that the user can be notified if the buffer is not large enough.
Support for 12 and 16-bit grayscale images is only available in the Document/Medical toolkits.
This function cannot be used in combination with redirecting I/O functions.
NOTES:
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.
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.
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
Win32, x64.
L_INT LMemoryFile__SaveBitmapBufferExample(LBitmapBase & Bitmap)
{
LMemoryFile MemoryFile;
LBuffer Buffer(5000); // 5000 bytes; supposed to be enough
L_SIZE_T dwFileSize;
L_INT nRet;
MemoryFile.SetBitmap(&Bitmap);
nRet = MemoryFile.SaveBitmapBuffer(&Buffer,
&dwFileSize,
FILE_TIF,
0,
SAVEFILE_FIXEDPALETTE,
NULL);
if (nRet == SUCCESS)
{
L_TCHAR szFileSize[100];
wsprintf(szFileSize, TEXT("The file size in memory is: %d"), dwFileSize);
MessageBox(NULL, szFileSize, TEXT("Testing"), MB_OK);
}
return nRet;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document