Loading and Saving Images

LEADTOOLS provides many options when loading and saving image files. Nevertheless, the code can be as simple as the following, which loads a LEAD compressed file and saves it as a Windows BMP file:

BITMAPHANDLE TmpBitmap;    /* Bitmap handle for the temporary bitmap */
FILEINFO  FileInfo;    /* File Information*/
/* Obtain image file information */
L_FileInfo
(TEXT("image3.cmp"), &FileInfo, sizeof(FILEINFO), 0, NULL);

/* Load a bitmap at its own bits per pixel  */
L_LoadBitmap
 (TEXT("image3.cmp"), &TmpBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL);

/* Save the image as a 24-bit Windows BMP file */
L_SaveBitmap
(TEXT("TEST.BMP"), &TmpBitmap, FILE_BMP, 24, 0, NULL);

/* Free the temporary bitmap */
L_FreeBitmap
(&TmpBitmap);

LEADTOOLS also supports super compressed images. Only 1-bit and 24-bit bitmaps can be kept super compressed in memory. For more information, refer to Super Compressed Bitmaps.

You can load an image at its own color resolution, manipulate it, and display it, regardless of current video mode. You can also convert the image to a specific color resolution (bits per pixel) as you load or save it. If you want to convert while loading or saving, refer to Conversion Considerations.

Whether an image file is on disk or in memory, you can get information about the image before loading it. You can also handle file-format-specific information, such as the page number or physical resolution. The following topics provide more information about specific file formats:

Controlling Progressive Loads and Saves

Implementing GIF Features

Implementing PhotoCD and FlashPix Features

Implementing FlashPix Extension

Implementing JBIG Features

Implementing Exif Features

Implementing TIFF Comments and Tags

Working with Markers

Multi-page File Formats

Working with the RAW File Filter

You can supply the input for a load operation or the output of a save operation, and you can add processing, such as a paint-while-load feature. Using Callback Functions describes these features. Callbacks lists the functions that you can supply.

You can control the execution of a load procedure as you supply transmitted image data. Refer to the L_StartFeedLoad, L_FeedLoad, and L_StopFeedLoad functions.

When working with multi-page files, you can delete individual pages within the file using L_DeletePage.

To load an image from a file, into a bitmap, and resize the bitmap as it loads, call L_LoadBitmapResize.

To save a bitmap to a file in a memory buffer, use L_SaveBitmapBuffer or L_SaveFileBuffer. The L_SaveFileBuffer uses an optional callback function to allow additional processing of the saved material.

PSD file formats support layers. LEADTOOLS provides the L_LoadLayer function to allow the loading of an individual layer. PSD files can also be saved with layer information by calling L_SaveBitmapWithLayers.

When loading DJVU files, you can use the L_GetDJVOptions to get the current values for the control options used by LEADTOOLS when loading a DJVU file. You can then use L_SetDJVOptions to change the values for the control options.

When loading HPGL files, you can use the L_GetPLTOptions to get the current values for the control options used by LEADTOOLS when loading an HPGL file. You can then use L_SetPLTOptions to change the values for the control options.

When loading RTF files, you can use the L_GetRTFOptions to get the current values for the control options used by LEADTOOLS when loading an RTF file. You can then use L_SetRTFOptions to change the values for the control options.

LEADTOOLS can load overlay files, which are usually PTOCA files, by either loading directly from the disk, or by calling an overlay callback function to get the overlay bitmap from the user. To set the callback function to use, as well as the methods and the order of those methods LEADTOOLS should use to load an overlay file, call L_SetOverlayCallback. To determine the current overlay callback function, which is the one last set using L_SetOverlayCallback, use L_GetOverlayCallback. This overlay callback must adhere to the function syntax specified in OVERLAYCALLBACK.

LEADTOOLS also lets you load embedded ICC profiles. These profiles can be loaded from JPEG, TIFF or EPS files. Before loading an ICC profile, an MEMICCPROFILE structure must be initialized by calling L_InitICCProfile. Then, the profile itself can be loaded by calling L_LoadICCProfile. When the structure that contains the loaded profile is no longer needed, the memory must be freed by calling L_FreeICCProfile.

When loading PTOCA and AFP:PTOCA files, you can use the L_GetPTKOptions to get the current values for the control options used by LEADTOOLS when loading a PTOCA file. You can then use L_SetPTKOptions to change the values for the control options.

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

Regions are saved automatically inside TIFF files. For more information, refer to Saving a Region.

Please note that the Document/Medical editions also support the loading and saving of Mixed Raster Content (MRC) files. The Mixed Raster Content format was defined for use for color and grayscale fax as part of the RFC-2301, File Format for Internet Fax. The Mixed Raster Content mode (T.44) enables different coding methods and resolutions to be used within a single page by defining a 3-layer image model for structuring and combining the scanned image data. For more information, refer to the LEADTOOLS Mixed Raster Content (MRC) API Help File.

When saving a JBIG2 file, you can use the L_GetJBIG2Options to get the current values for the control options used by LEADTOOLS. You can also use L_SetJBIG2Options to change the values for the control options before saving the JBIG2 file.

When loading TXT files, you can use the L_GetTXTOptions to get the current values for the control options used by LEADTOOLS. You can also use L_SetTXTOptions to change the values for the control options before loading the TXT files.

LEADTOOLS will attempt to load corrupted files, so you can see at least a portion of the image. For these images, the load functions will return SUCCESS, but L_GetLoadStatus will return an error code.

LEADTOOLS supports loading TIFF CMYK files without converting the data to BGR. This is done by loading each CMYK plane as a separate LEADTOOLS bitmap using L_LoadFileCMYKArray. To save the bitmap as TIFF CMYK, call L_SaveFileCMYKArray.

When loading 8-bits PNG files, you can use the L_GetPNGTRNS to get the current values for the transparency data used by LEADTOOLS. You can also use L_SetPNGTRNS to change the values for the transparency data before saving the 8-bits PNG files.

When obtaining image file information, you can use the L_GetFilterInfo to get the current information for a specific filter, or use L_GetFilterListInfo to get an array of information for all filters used by LEADTOOLS. You can also use L_SetFilterInfo to change all the filters information before obtaining images files information. To free all the filters information allocated by calling the L_GetFilterListInfo or L_GetFilterInfo functions, the user should call the L_FreeFilterInfo.