LEADTOOLS Raster Imaging C DLL Help > Getting Started > For Beginners > 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, 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);
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.
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 PhotoCD and FlashPix Features
Implementing FlashPix Extension
Implementing TIFF Comments and Tags
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.
You can control the execution of a file info procedure as you supply transmitted image data. Refer to the L_StartFeedInfo, L_FeedInfo, and L_StopFeedInfo 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.
PSD file formats support channels. LEADTOOLS provides the L_LoadChannel to allow the loading channel from a file.
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. You can get an EMF handle from a specific page in RTF file by using the L_GetEmfHandleFromRtf function.
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.
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 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 DLL 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.
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.
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.
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 L_FileInfo and check the bIsDocFile member of the result FILEINFO structure. When rasterization document files, you can use the L_GetRasterizeDocOptions to get the current values for the control options used by LEADTOOLS. You can also use L_SetRasterizeDocOptions to change the values for the control options before rasterization document files. Use the L_GetRasterPdfInfo to get information for a raster PDF file created by LEADTOOLS Raster PDF plugin.
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, 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.
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.
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.
NOTE: To save a region inside a TIFF file, you must have an unlocked Vector, Document, or Medical Imaging license.
Saving Colored Images as Bitonal
LEADTOOLS has the capability of automatically saving 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 bitonal with and without dithering.
static L_VOID Test(L_TCHAR* coloredImageFileName)
{
// SAVEFILEOPTION does not use ESO_USEDITHERINGMETHOD by defaultt
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);
}