L_SaveFile

#include "l_bitmap.h"

L_INT EXT_FUNCTION L_SaveFile(pszFile, pBitmap, nFormat, nBitsPerPixel, nQFactor, uFlags, pfnCallback, pUserData, pSaveOptions)

L_TCHAR, L_FAR * pszFile;

/* name of the image file to save */

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_UINT uFlags;

/* flags that determine function behavior */

FILESAVECALLBACK pfnCallback;

/* optional callback function */

L_VOID L_FAR * pUserData;

/* pointer to more parameters for the callback */

pSAVEFILEOPTION pSaveOptions;

/* pointer to optional extended save options */

Creates a file in any of the supported compressed or uncompressed formats, using input data that your callback function supplies.

Parameter

Description

pszFile

Character string containing the name of the image file to save.

pBitmap

Pointer to the bitmap handle that describes the data to be saved. The bitmap handle can contain the actual data, but does not have to, since your callback function can supply the data.

 

However, the bitmap handle must contain values for the following fields: Width, Height, BitsPerPixel, BytesPerLine, nColors, ViewPerspective, Order, and DitheringMethod. (The BytesPerLine value must be a multiple of four.)

nFormat

Output file format. For valid values, refer to Formats of Output Files.

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, 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 L_SaveFile. 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 multi-page file. It appends the image as the last one in the file. You can save multi-page images in PCX, GIF, and most TIFF file formats (including JTIF, but excluding EXIF).

pfnCallback

Optional callback function for additional processing.

 

image\sqrblit.gif If you do not provide a callback function, use NULL as the value of this parameter.

 

image\sqrblit.gif If you do provide a callback function, use the function pointer as the value of this parameter.

 

The callback function must adhere to the syntax described in FILESAVECALLBACK Function.

pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

 

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID L_FAR *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.

 

If the additional parameters are not needed, you can pass NULL in this parameter.

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 you provide a callback function, it must supply the image data. It can also do other useful things, such as updating a status bar.

If you do not provide a callback function, this function saves data from the specified 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 Imaging editions .

Note:

More options are available in the SAVEFILEOPTION structure.

Note:

More options are available in the SAVEFILEOPTION structure.

Note:

If SAVE_MULTIPAGE is passed in uFlags, this takes precedence over the ESO_REPLACEPAGE or ESO_INSERTPAGE flags set in SAVEFILEOPTION.

Note: For information about loading and saving large TIFF files faster, refer to Loading and Saving Large TIFF Files.

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.

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

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
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 95 / 98 / Me, Windows 2000 / XP, Windows CE.

See Also

Functions:

L_SaveBitmap, L_SaveFileOffset, L_CompressBitmapWithStamp, L_FileConvert, L_SetExtFileOption, 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

 

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 SAVECB example.

/****************************************************************************************
This example uses L_SaveFile with a callback function that supplies the image data.
Refer to the FILESAVECALLBACK function to see how the callback function supplies 
the image data.

The sample code uses the following global declarations: */

HINSTANCE hInst;   /* Current instance of the application, set by the InitInstance function */
BITMAPHANDLE LeadBitmap;   /* Bitmap handle to hold the loaded image */

/* Prototype for the FILESAVECALLBACK function */
L_INT L_EXPORT EXT_CALLBACK SaveImageCB (pBITMAPHANDLE pBitmap,
                                   L_UCHAR L_FAR * pBuffer,
                                   L_UINT nRowBegin,
                                   L_UINT nRowsToGet,
                                   L_VOID L_FAR * pUserData);
/****************************************************************************************/
void TestSaveFunction(void)
{
   L_INT nRet; /* Return value */
   L_TCHAR szMessage[80]; /* Buffer for the MessageBox string */
   FILESAVECALLBACK lpfnSaveCallback; 
   /* Set the callback function for the L_SaveFile function.*/
   lpfnSaveCallback = (FILESAVECALLBACK) MakeProcInstance(
      (FARPROC) SaveImageCB, hInst );
   /* Set the dithering method for the save */
   LeadBitmap.DitheringMethod = FLOYD_STEIN_DITHERING;
   /* Save the file as an 8-bit Windows BMP file with a fixed palette */
   nRet = L_SaveFile(TEXT("TEST2.BMP"), 
                     &LeadBitmap,
                     FILE_BMP, 8, 0, 
                     SAVEFILE_FIXEDPALETTE,
                     lpfnSaveCallback,
                     NULL,
                     NULL);
   FreeProcInstance ((FARPROC) lpfnSaveCallback);
   /* Notify the user with a message box */
   if (nRet == SUCCESS)
   {
      MessageBox (NULL, TEXT("File was saved"), TEXT("Notice"), MB_OK);
   }
   else
   {
      wsprintf (szMessage, TEXT("Error %d saving the file"), nRet);
      MessageBox (NULL, szMessage, TEXT("Error"), MB_OK);
   }
   return;
}