LMemoryFile::SaveFileBuffer
#include "ltwrappr.h"
virtual L_INT LMemoryFile::SaveFileBuffer(pLBuffer, puFileSize, nFormat, nBitsPerPixel, nQFactor, uFlags, pSaveOptions)
LBuffer * pLBuffer; |
/* pointer to an LBuffer object */ |
L_SIZE_T * puFileSize; |
/* pointer to a variable */ |
L_INT nFormat; |
/* output file format */ |
L_INT nBitsPerPixel; |
/* resulting file's pixel depth */ |
L_INT nQFactor; |
/* quality factor */ |
L_UINT uFlags; |
/* flags that determine function behavior */ |
pSAVEFILEOPTION pSaveOptions; |
/* pointer to optional extended save options */ |
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.
Parameter |
Description |
|
pLBuffer |
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::SaveFileBufferCallBack is called to allow the user to reallocate the buffer. |
|
puFileSize |
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. |
|
nFormat |
Output file format. For valid values, refer to Summary of File Formats. |
|
nBitsPerPixel |
Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Summary of File Formats. 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. |
|
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, and FILE_EXIF_JPEG. Qfactor is a number that determines the degree of loss in the compression process. |
|
|
For possible values, refer to Compression Quality Factors. |
|
uFlags |
Binary flags that determine the behavior of LMemoryFile::SaveFileBuffer. You can specify one of the following values: |
|
|
Value |
Meaning |
|
SAVEFILE_FIXEDPALETTE |
[0x0001] The function uses the fixed palette for images that are saved as 8 bits per pixel or less. |
|
SAVEFILE_OPTIMIZEDPALETTE |
[0x0002] The function uses the individual image's optimized palette for images that are saved as 8 bits per pixel or less. The optimized palette must be included in the bitmap handle. |
|
SAVEFILE_MULTIPAGE |
[0x0004] The function saves the image in a multipage file. It appends the image as the last one in the file. You can save multipage images in PCX, GIF, and most TIFF file formats (including JTIF, but excluding EXIF). |
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
LMemoryFile::SaveFileBuffer saves the class object's associated bitmap to an LBuffer object. The output can be in any of the supported, compressed or uncompressed file formats. The user is responsible for allocating/reallocating buffers. If the buffer of the LBuffer object is not large enough, the LMemoryFile::SaveFileBufferCallBack is called so the user can re-allocate the buffer.
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 estimatethis 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::SaveFileBufferCallBack 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 the redirecting I/O functions.
Note: |
More options are available in the SAVEFILEOPTION structure. |
Note: |
FPX, PCD, AWD and AVI files cannot be saved to memory. |
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.
Required DLLs and Libraries
LTFIL For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
See Also
Functions: |
LMemoryFile::SaveBitmapBuffer, LMemoryFile::SaveFileBufferCallBack, LMemoryFile::SaveFileCallBack, LMemoryFile::SaveBitmapBufferCallBack, LMemoryFile::Save, Class Members |
Topics: |
|
|
|
|
|
|
|
|
Example
L_INT LMemoryFile__SaveFileBufferExample(LBitmapBase & Bitmap) { LMemoryFile MemoryFile; LBuffer Buffer(1000); // 1000 bytes; supposed to be enough L_SIZE_T dwFileSize; L_INT nRet; MemoryFile.SetBitmap(&Bitmap); nRet = MemoryFile.SaveFileBuffer(&Buffer, &dwFileSize, FILE_TIF, 0, QS, 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; }