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:
// 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();
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.
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.
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 following topics provide more information about specific file formats:
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.
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.
The desired width and height can be passed to the Load
method to resize the image to new dimensions as it is loaded.
The MrcSegmenter.LoadImage
method loads files saved as the LEAD Proprietary T44 Format or Standard T44 Format.
Headerless raw and fax image-data type files can be loaded and saved using the Raw filter codec (Leadtools.Codecs.Raw.dll).
The SaveImage
event provides facilitates additional processing of the saved file.
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 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.
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.
Whenever an image's color depth is reduced to 8-bits per pixel or less, a dithering method may come 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 only black and white.
To enable dithering, you must set the dithering method inside the RasterImage
to the required value and then instruct RasterCodecs
to use this value when saving the image. The following example will load a 24-bpp image and save it as bitonal with and without dithering.
private static void Test(RasterCodecs codecs, string coloredImageFileName)
{
// RasterCodecs.Options.Save.UseImageDitheringMethod is false by default
RasterImage image = codecs.Load(coloredImageFileName);
// Save it with no dithering options
codecs.Save(image, @"C:\NotDithered.tif", RasterImageFormat.CcittGroup4, 1);
// Change the image dithering method to FloydStein
image.DitheringMethod = RasterDitheringMethod.FloydStein;
// Use the image dithering method when saving
codecs.Options.Save.UseImageDitheringMethod = true;
// Save it again
codecs.Save(image, @"C:\Dithered.tif", RasterImageFormat.CcittGroup4, 1);
image.Dispose();
}
Private Shared Sub Test(ByVal codecs As RasterCodecs, ByVal coloredImageFileName As String)
' RasterCodecs.Options.Save.UseImageDitheringMethod is false by default
Dim image As RasterImage = codecs.Load(coloredImageFileName)
' Save it with no dithering options
codecs.Save(image, "C:\NotDithered.tif", RasterImageFormat.CcittGroup4, 1)
' Change the image dithering method to FloydStein
image.DitheringMethod = RasterDitheringMethod.FloydStein
' Use the image dithering method when saving
codecs.Options.Save.UseImageDitheringMethod = True
' Save it again
codecs.Save(image, "C:\Dithered.tif", RasterImageFormat.CcittGroup4, 1)
image.Dispose()
End Sub
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 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/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.
LEADTOOLS provides extensive support for WPF and Silverlight. To learn how to display LEADTOOLS images in WPF/Silverlight, as well as convert them to and from WPF/Silverlight images, refer to RasterImage and Wpf/Silverlight
Products |
Support |
Feedback: Loading and Saving Images |
Introduction |
Help Version 19.0.2017.6.21
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.