LEADTOOLS provides many options for 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 = { 0 }; /* Bitmap handle for the temporary bitmap */
FILEINFO FileInfo = { 0 }; /* 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, 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 has many functions that provide file information, including the following functions:
FILEINFO - Structure containing file information.
L_FileInfo - Obtains image file information.
L_FileInfoMemory - Obtains image file information from a file in memory.
L_FeedInfo - Supplies image data to the file-info process from a buffer that you provide.
L_GetFilterInfo - Gets the current information for a specific filter.
L_GetFilterListInfo - Gets information for an array of filters used by LEADTOOLS.
L_SetFilterInfo - Changes information for all of the fillers.
L_FreeFilterInfo - Frees the memory allocated by calling the L_GetFilterListInfo or L_GetFilterInfo function.
Whether an image file is on disk or in memory, you can get information about the image before loading it. For more information, see Raster Image Functions: Getting and Setting File Information.
Regardless of the video mode, with LEADTOOLS functions you can load an image at its own color resolution, manipulate it, and display it. You can also handle file-format-specific information, such as the page number or physical resolution.
LEADTOOLS will attempt to load corrupted files (so you can see at least a portion of the image). For such images, the load functions will return SUCCESS, but L_GetLoadStatus will return an error code.
LEADTOOLS 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.
Support for loading images is provided by the following functions:
L_LoadBitmap - Loads an image from a file into a bitmap (a simpler, higher level version of L_LoadFile).
L_LoadFile - The core function for loading bitmaps. It provides the most flexibility and functionality: all other load functions eventually call this function.
L_LoadFileOffset - Loads an image from a file using a callback function, letting you specify the location of the image data within the file.
L_LoadMemory - Loads in image from a file in memory.
L_FeedLoad - Supplies image data to the file-load process from a buffer that you provide.
L_LoadSvg - Loads a page from an image, document or vector file as an SVG file. Support for this function is available in the Document and Medical Imaging toolkits.
L_LoadBitmapResize - Loads an image from a file into a bitmap, resizing it as it loads.
L_SaveBitmapBuffer or L_SaveFileBuffer - Saves a bitmap to a file in a memory buffer. The L_SaveFileBuffer function uses an optional callback to allow additional processing of the saved material.
L_StartFeedLoad, L_FeedLoad, and L_StopFeedLoad - Controls the execution of a load or file information procedure as you supply transmitted image data.
For more information, refer to Loading and Saving Large TIFF/BigTIFF Files and Using Filter Data to Speed up Loading Large Files.
Conversion from one file format to another can take place when loading or saving a file, or when performing file-to-file conversion. Converting can include the simultaneous resizing of an image. It can also change the image's bits per pixel. Of course, conversion takes longer when resizing or changing the bits per pixel is included. When reducing a file to a 4- or 8-bit format, LEADTOOLS must reduce the number of colors. Therefore, the image cannot be converted back to the original image format and retain its original colors. When converting from 24-bits or less to a 32-bit file, the alpha channel will be filled with zeros.
The LEADTOOLS SDK has its own data type for storing and accessing image data (Each target platform (for example, Windows, Android, etc.), also has its own native image data structure or class.) To make it easy to work with both the LEADTOOLS image data type and the target platform’s native image data type, the LEADTOOLS SDK provides functions for converting between the two.
The following platforms are supported:
LEADTOOLS functions make it possible to perform the following tasks:
Convert from the LEADTOOLS image data type to the target platform’s native image data type.
Convert from the target platform’s native image data type to the LEADTOOLS image data type.
If you load a LEAD or JPEG file and convert it to 8 bits per pixel while loading, LEADTOOLS dithers the image using the fixed palette. To use an optimized palette, you should first load it as a 24-bit bitmap; then use L_ColorResBitmap to reduce the image using an optimized palette.
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 up the callback function for use, including 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 (the one last set using L_SetOverlayCallback), use L_GetOverlayCallback. This overlay callback must adhere to the function syntax specified in OVERLAYCALLBACK.
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.
Work with multipage files by using the following functions:
L_LoadBitmapList - Creates a bitmap list and loads bitmaps from a multi-page file into the list.
L_SaveBitmapList - Saves a list of bitmaps in a multipage file.
L_DeletePage - Deletes individual pages within a multipage file.
The bitmap list functions can also be used:
For more information, refer to Loading and Saving Large TIFF/BigTIFF Files and Using Filter Data to Speed up Loading Large Files.
LEADTOOLS supports a vast number of image formats. For the most current listing of all supported file formats, see: Supported File Formats
The following topics provide more information about specific file formats:
Controlling Progressive Loads and Saves
Implementing PhotoCD and FlashPix Features
Implementing FlashPix Extension
Implementing TIFF Comments and Tags
Working with the RAW File Filter
The LEADTOOLS toolkits have many functions to support specific file formats. They include:
PSD - PSD file formats support layers. LEADTOOLS provides the L_LoadLayer function to load an individual layer. PSD files can also be saved with layer information by calling L_SaveBitmapWithLayers. PSD file formats support channels. Use the L_LoadChannel function to load a channel from a file.
HPGL - 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.
PTOCA and AFP:PTOCA files - 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.
MRC - Please note that the Document and 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) C API Help File.
JBIG2 - 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.
LEADTOOLS provides support for loading a document as a raster image. Documents formats such as PDF, XPS, XLS, PST, RTF and Text do not contain physical width, height or resolution. It is up to the loader to specify the transformation from logical coordinates to physical pixels through a process called rasterization. Rasterization is the process of converting a document to a raster image. To determine whether a certain file on disk or memory contains a document file rather than a regular raster image, call L_FileInfo and look at the bIsDocFile member of the resulting FILEINFO structure. When rasterizing document files, use the L_GetRasterizeDocOptions to get current values for the control options used by LEADTOOLS. Use L_SetRasterizeDocOptions to set control option values before rasterizing document files.
PDF - Use the L_GetRasterPdfInfo to get information for a raster PDF file created by LEADTOOLS Raster PDF SDK.
RTF - 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. Get the EMF handle for a specific page in an RTF file by calling the L_GetEmfHandleFromRtf function.
TXT - 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.
PST - When loading PST files, you can use the L_GetPSTOptions to get the current values for the control options used by LEADTOOLS. You can also use L_SetPSTOptions to change the values for the control options before loading the PST files.
XPS - When loading XPS files, you can use the L_GetXPSOptions to get the current values for the control options used by LEADTOOLS. You can also use L_SetXPSOptions to change the values for the control options before loading the XPS files.
XLS - Microsoft Excel 2003 (XLS) files have no physical width or height in pixels. You can use RASTERIZEDOCOPTIONS to control how the final document is rendered as a raster image. When loading XLS files, you can use the L_GetXLSOptions to get the current values for the control options used by LEADTOOLS. You can also use L_SetXLSOptions to change the values for the control options before loading the XLS files.
TIFF - 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.
NOTE: To save a region inside a TIFF file, you must have an unlocked Document or Medical Imaging license.
PNG - When loading 8-bits PNG files, use the L_GetPNGTRNS to get the current values for the transparency data used by LEADTOOLS. Use L_SetPNGTRNS to change the values for the transparency data before saving the 8-bits PNG files.
ANZ - When loading ANZ (Analyze format) files, use the L_GetANZOptions to get the current values for the control options used by LEADTOOLS. Use L_SetANZOptions to change the values for the control options before loading the ANZ files.
DOC - When loading DOC files, use the L_GetDOCOptions to get the current values for the control options used by LEADTOOLS. Use L_SetDOCOptions to change the values for the control options before loading the DOC files.
When loading vector files, use the L_GetVectorOptions function to get the current values for the control options used by LEADTOOLS. Use the L_SetVectorOptions function to change the values for the control options before loading the vector files.
LEADTOOLS can automatically save a colored image (an image that has more than 1 bit/pixel) as bitonal (an image that has 1 bit/pixel). This is accomplished by passing "1" as the nBitsPerPixel parameter of L_SaveBitmap or L_SaveFile.
Whenever you reduce an image's color resolution to 8 bits per pixel or less, a dithering method comes into play. One alternative is to use a nearest-color match (no dithering), which means that the color of each pixel is changed to the palette color that most closely matches it. If the original image contains subtle color details, the result of a nearest-color match may have large blotches of color that are not very pleasing.
Dithering methods create the appearance of more subtle shades by mixing in pixels of different colors. This is similar to the way newspaper pictures produce the appearance of shades of gray, even though the only actual colors are black and white.
Starting with v17, LEADTOOLS will not use dithering when saving a colored image as bitonal (1-bit/pixel) by default. This will guarantee that the final bitonal image contains the clearest representation of the original text in the image and provides the best input for document-based recognition methods such as OCR and Barcode.
To enable dithering, you must set the dithering method inside the BITMAPHANDLE to the required value and then instruct the save functions to use this value when saving the image. The following example will load a 24bpp image and save it as a bitonal image, both with and without dithering.
static L_VOID Test(L_TCHAR* coloredImageFileName)
{
// SAVEFILEOPTION does not use ESO_USEDITHERINGMETHOD by default
BITMAPHANDLE bitmapHandle = {0};
L_LoadBitmap(coloredImageFileName, &bitmapHandle, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
// Save it with no dithering options
L_SaveBitmap(L"C:\\NotDithered.tif", &bitmapHandle, FILE_CCITT_GROUP4, 1, 1, NULL);
// Change the bitmap dithering method to FloydStein
bitmapHandle.DitheringMethod = FLOYD_STEIN_DITHERING;
// Use the bitmap dithering method when saving
SAVEFILEOPTION saveOptions = {0};
L_GetDefaultSaveFileOption(&saveOptions, sizeof(SAVEFILEOPTION));
saveOptions.Flags |= ESO_USEDITHERINGMETHOD;
// Save it again
L_SaveBitmap(L"C:\\Dithered.tif", &bitmapHandle, FILE_CCITT_GROUP4, 1, 1, &saveOptions);
L_FreeBitmap(&bitmapHandle);
}