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:
LBitmapBase TmpBitmap; /* LBitmapBase object for the temporary bitmap */
/* Load a bitmap at its own bits per pixel */
TmpBitmap.Load(TEXT("v:\\images\\eagle.cmp"), 0, ORDER_BGR);
/* Save the image as a 24-bit Windows BMP file */
TmpBitmap.Save(TEXT("d:\\temp\\test.bmp"), FILE_BMP, 24, 0, 0);
LEADTOOLS has many functions that provide file information, including the following functions:
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 LBitmapBase::GetLoadStatus will return an error code.
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.
Support for loading images is provided by the following functions:
LEADTOOLS toolkits offer many ways to save a file on disk, as follows:
There are also several ways to save a file in memory. LMemoryFile::SaveBitmapBuffer or LMemoryFile::SaveFileBuffer - Saves a bitmap to a file in a memory buffer. The LMemoryFile::SaveFileBuffer function uses an optional LMemoryFile::SaveFileBufferCallBack to allow additional processing of the saved material. This is useful when the buffer of the LBuffer object used by LMemoryFile::SaveBitmapBuffer is not large enough to accommodate the file in memory. The callback makes it possible to reallocate the buffer size. In addition, the LMemoryFile::SaveFileBuffer also calls the LMemoryFile::SaveFileCallBack to the image data from the specified bitmap. The LMemoryFile::SaveFileCallBack can be overridden if the user wants to supply the image data to save.
For information on saving bitmaps that have been window leveled, refer to Saving Window-Leveled Bitmaps.
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 zeroes.
The LEADTOOLS SDK has its own data type for storing and accessing image data (Each target platform (ex. 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 LBitmapBase::ColorRes 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 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 LBase::EnableOverlayCallBack. To determine the current overlay callback function, (which is the one last set), use LBase::EnableOverlayCallBack. This overlay callback must adhere to the function syntax specified in LBase::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:
The bitmap list functions can also be used:
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:
The LEADTOOLS toolkits have many functions to support specific file formats. They include:
LEADTOOLS provides support for loading a document as a raster image. Documents formats such as PDF, XPS, XLS, 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 check if a certain file on disk or memory contains a document file rather than a regular raster image, call LFile::GetInfo and check the bIsDocFile member of the result FILEINFO structure. To obtain information about a raster PDF file created by LEADTOOLS Raster PDF plugin, call LFile::GetRasterPdfInfo. When rasterizing document files, you can use the LFileSettings::GetRasterizeDocOptions to get the current values for the control options used by LEADTOOLS. You can also use LFileSettings::SetRasterizeDocOptions to change the values for the control options before rasterizing document files.
NOTE: To save a region inside a TIFF file, you must have an unlocked Vector, Document, or Medical Imaging license.
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 LBitmapBase::Save or LFile::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.
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 recommended when converting colored images containing text for document processing such as OCR and Barcode. The resulting 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), first set the dithering method to Floyd-Stein by calling LBitmapBase::SetDitheringMethod with the uDitheringMethod parameter set to FLOYD_STEIN_DITHERING. Next, set the Flags member of the SAVEFILEOPTION structure to ESO_USEDITHERINGMETHOD. Then, call LBitmapBase::Save or LFile::SaveFile.
Does your application require document recognition or conversion, but its implementation language is preventing you from using LEADTOOLS directly? Consider using the LEADTOOLS Cloud Services Web API instead. It is a high-powered and scalable Web API. Its hassle-free interface can be used to integrate advanced OCR, barcode, MICR, and document conversion into any application.