Loading and Saving Images

Powerful, but Easy to Use

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:

C#
VB
Java
// Create a new instance of the RasterCodecs class 
Leadtools.Codecs.RasterCodecs codecs = new Leadtools.Codecs.RasterCodecs(); 
// Load an image at its own bits per pixel 
Leadtools.RasterImage image = codecs.Load(@"Test.cmp",0,Leadtools.Codecs.CodecsLoadByteOrder.Bgr,1,1); 
// Save the image as a 24-bit Windows BMP file 
codecs.Save(image,@"Test.bmp",Leadtools.RasterImageFormat.Bmp,24,1,1,1,Leadtools.Codecs.CodecsSavePageMode.Overwrite); 
// Dispose of the objects we created 
image.Dispose(); 
codecs.Dispose(); 
' Create a new instance of the RasterCodecs class 
Dim codecs As New Leadtools.Codecs.RasterCodecs() 
' Load an image at its own bits per pixel 
Dim image As Leadtools.RasterImage = codecs.Load("Test.cmp",0,Leadtools.Codecs.CodecsLoadByteOrder.Bgr,1,1) 
' Save the image as a 24-bit Windows BMP file 
codecs.Save(image,"Test.bmp",Leadtools.RasterImageFormat.Bmp,24,1,1,1,Leadtools.Codecs.CodecsSavePageMode.Overwrite) 
' Dispose of the objects we created 
image.Dispose() 
codecs.Dispose() 
// Create a new instance of the RasterCodecs class  
leadtools.codecs.RasterCodecs codecs = new leadtools.codecs.RasterCodecs(); 
// Load an image at its own bits per pixel 
leadtools.RasterImage image = codecs.load("Test.cmp",0,leadtools.codecs.CodecsLoadByteOrder.BGR,1,1); 
// Save the image as a 24-bit Windows BMP file 
codecs.save(image,"Test.bmp",leadtools.RasterImageFormat.BMP,24,1,1,1,leadtools.codecs.CodecsSavePageMode.OVERWRITE); 
// Dispose of the objects we created  
image.dispose(); 
codecs.dispose(); 

The following table describes some of the capabilities available when loading and saving images:

Feature Description
Super Compressed Image Data LEADTOOLS supports super compressed image data. Only 1-bit and 24-bit images can be kept super compressed in memory. For more information, refer to Super Compressed Images.
Color Depth Regardless of current system display color depth, an image can be loaded and manipulated at its native color depth and then displayed. LEADTOOLS can automatically adjust to the display device without changing the image data. An image can also be converted to a specific color depth (bits per pixel) as it is loaded or saved. To learn more about how to convert while loading or saving, refer to Conversion Considerations.
File Information Before Loading Whether an image file is on disk or in memory, LEADTOOLS can provide information about the image before loading it. LEADTOOLS can also provide file-format-specific information, such as the page number or physical resolution. The FastFileInfo provides functionality to determine if a file will be rejected if the signature does not match one of the known file format signatures. As a result, the file filter codecs will not be unnecessarily loaded and called. 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. For more information about specific file formats, refer to Controlling Progressive Loads and Saves, Implementing Exif Features, and Implementing TIFF Comments and Tags.
Feed Load (Streaming Data) LEADTOOLS provides a mechanism to load image data as it is supplied (streamed). For more information, refer to the RasterCodecs.StartFeedLoad, RasterCodecs.FeedLoad, and RasterCodecs.StopFeedLoad methods.
Resize During Load The desired width and height can be passed to the Load method to resize the image to the specified dimensions as it is loaded.
T44 File Format The MrcSegmenter.LoadImage method loads files saved as the LEAD Proprietary T44 Format or Standard T44 Format.
Headerless Raw and Fax Image Data Headerless raw and fax image-data type files can be loaded and saved using the Raw filter codec (Leadtools.Codecs.Raw.dll).
Process Image as it is Saved The SaveImage event facilitates additional processing of the saved file.
Regions of Interest Regions are automatically saved inside TIFF files. For more information, refer to Saving a Region. Note, however, that the functionality to save a region inside a TIFF file requires a Document Imaging or Medical Imaging toolkit.
Window-Leveling Window-leveling converts extended grayscale (12- or 16-bit) image data to 8-bit grayscale or 24-bit RGB image data. Only TIFF and DICOM file formats are capable of storing extended grayscale image data. For more information, refer to Saving Window-Leveled Images.
CMYK Image Data LEADTOOLS supports loading TIFF CMYK files without converting the data to BGR. This is done by loading each CMYK plane as a separate page in an Image using LoadCmykPlanes. To save the planes as TIFF CMYK, call SaveCmykPlanes. For more information, refer to Handling CMYK Files as Separate Images.
Color Reduction Frequently it is necessary to reduce the number of colors being used in an image. If the color depth is reduced to 8-bits per pixel or less, dithering can be used to improve the appearance of the image by mixing colors together to simulate unavailable colors. For more information, refer to Introduction: Color Resolution and Dithering.
Saving Color Image Data as Bitonal LEADTOOLS can automatically save a colored image (an image that has more than 1 bit/pixel) as bitonal (an image that has 1-bit per pixel). This is accomplished by passing 1 as the value of the bitsPerPixel parameter of the various RasterCodecs.Save methods. Due to the nature of the content of most bitonal images (usually text), dithering is not desirable. Therefore, LEADTOOLS does not use dithering when saving colored image data as bitonal (1-bit per pixel) by default. This increases the likelihood that the final bitonal image will contain the clearest representation of the original text in the image to provide the best input for recognition methods such as OCR and barcode.
Windows Presentation Foundation (WPF) Support LEADTOOLS provides extensive support for WPF. To learn how to display LEADTOOLS images in WPF, as well as convert them to and from WPF images, refer to RasterImage and Wpf.

References

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document