LFile::SaveOffset

#include "ltwrappr.h"

virtual L_INT LFile::SaveOffset(fd, nOffsetBegin, pnSizeWritten, nFormat, nBitsPerPixel=0, nQFactor=2, uFlags=0, pSaveFileOption=NULL)

L_HFILE fd;

/* file handle */

L_SSIZE_T nOffsetBegin;

/* offset within the specified file */

L_SSIZE_T * pnSizeWritten;

/* address of a variable to be updated */

L_INT nFormat;

/* output file format */

L_INT nBitsPerPixel;

/* resulting file's pixel depth */

L_INT nQFactor;

/* quality control */

L_INT uFlags;

/* flags that indicate the behavior of the function */

pSAVEFILEOPTION pSaveFileOption;

/* pointer to optional extended save options */

Saves a bitmap to a file in any supported format letting you specify an offset within the file to begin saving. This enables you to embed an image file in another file.

Parameter

Description

fd

The Windows file handle of the file to save Files To Be Included With Your Application.

nOffsetBegin

The offset within the specified file to embed the saved image file. For example, if you specify 5, then 5 bytes of other data will precede the embedded file.

pnSizeWritten

Address of a variable to be updated with the size of the embedded image file.

nFormat

Output file format. For valid values, refer to .

nBitsPerPixel

Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to the file format topic for that format (See the lists in Files and 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 returns 5, the file will be stored as 24-bit. Likewise, if LBitmapBase::GetBitsPerPixel returns 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.

uFlags

Binary flags that determine the behavior of LFile::SaveFile. Possible values are:

 

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

pSaveFileOption

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

This function overwrites existing data at the specified location in the file.

You can use this function to update an image that you loaded with the LFile::LoadOffset function.

The offset is specified in bytes. You must open the file and get a Windows file handle before calling this function. You must also declare a variable to receive the resulting size of the embedded image file (in the nSizeWritten parameter).

You can override the LFile::SaveFileCallBack virtual function to supply the image data.

If you do not override the callback function, this function saves data from the class object's associated bitmap.

If you use a callback and save the bitmap as a MacPaint (MAC) file, the image to be saved must have a width of 576 and a height of 720 (the required dimensions of that format).

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

Note: More options are available in the SAVEFILEOPTION structure.

Note: If SAVE_MULTIPAGE is passed in uFlags, this takes precedence over the EFO_REPLACEPAGE or EFO_INSERTPAGE flags set in SAVEFILEOPTION.

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.

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

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.

See Also

Functions:

LFile::ReadCommentOffset, LFile::Compact, Class Members

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

Example

For an example, refer to LFile::LoadOffset.