Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.8.30
|
Leadtools.Codecs Namespace > RasterCodecs Class > Save Method : Save(RasterImage,Stream,RasterImageFormat,Int32) Method |
public void Save( RasterImage image, Stream stream, RasterImageFormat format, int bitsPerPixel )
'Declaration
Public Overloads Sub Save( _ ByVal image As RasterImage, _ ByVal stream As Stream, _ ByVal format As RasterImageFormat, _ ByVal bitsPerPixel As Integer _ )
'Usage
Dim instance As RasterCodecs Dim image As RasterImage Dim stream As Stream Dim format As RasterImageFormat Dim bitsPerPixel As Integer instance.Save(image, stream, format, bitsPerPixel)
public void Save( RasterImage image, Stream stream, RasterImageFormat format, int bitsPerPixel )
- (BOOL)save:(LTRasterImage *)image stream:(LTLeadStream *)stream format:(LTRasterImageFormat)format bitsPerPixel:(NSInteger)bitsPerPixel error:(NSError **)error
public void save(RasterImage image, ILeadStream stream, RasterImageFormat format, int bitsPerPixel)
function Leadtools.Codecs.RasterCodecs.Save(RasterImage,Stream,RasterImageFormat,Int32)( image , stream , format , bitsPerPixel )
public: void Save( RasterImage^ image, Stream^ stream, RasterImageFormat format, int bitsPerPixel )
If the output file format supports multi-page and then all the pages in image will be saved to the file.
If the image is 8 bits per pixel or greater, use the LEAD CMP format or one of the JPEG (JTIF or JFIF) formats to save disk space.
If the image is 1-bit per pixel, use the LEAD 1-bit format or a CCITT Group 3 or 4 format to save disk space.
If the image has a region, the region stored in the image will be saved, if the image is saved as one of the TIFF file formats. For more information, refer to Saving A Region. Note, however, that the ability to save a region inside a TIFF file must be unlocked. This requires a Document Imaging or Document Imaging toolkit.
Only TIFF and DICOM file formats are capable of saving images that have been window-leveled. Images can be window-leveled by calling RasterImage.WindowLevel and specifying RasterWindowLevelMode.PaintAndProcessing, by using the WindowLevelCommand or by loading an image from a file format that supports Window Leveling. If a window-leveled image is saved as any other file format, the image data will be converted before being saved. For more information, refer to Saving Window-Leveled Images.
Use the CodecsSaveOptions class to set up other save options parameters before calling this method.
Use FormatSupportsMultipageSave to determine if the format supports saving into a multi-page file.
Use the SaveImage event to provide progress feedback or to set or modify the saved image data.
This method supports signed data images, but only DICOM and TIFF formats support signed data. This method will throw an exception if you attempt to save a signed image to a format other than DICOM or TIFF.
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 RasterCodecs object will not use any dithering when converting the image data. This is done because dithering is not the 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) use CodecsSaveOptions.UseImageDitheringMethod along with RasterImage.DitheringMethod as illustrated below:
// 'codecs' is the RasterCodecs to use when saving
// 'image' is a colored RasterImage object
// Setup FloydStein dithering:
codecs.Options.Save.UseImageDitheringMethod = true;
image.DitheringMethod = RasterDitheringMethod.FloydStein;
// Save the image as 1-bpp with auto-dithering:
codecs.Save(image, fileName, RasterImageFormat.Tif, 1);
For information about quality factors, refer to Compression Quality Factors.
This example will load a 24 bits/pixel CMP image and save it to a stream as 1 bits/pixel TIF image.
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Imports Leadtools.Drawing Imports Leadtools.Svg Public Sub SaveStream1Example() Dim codecs As RasterCodecs = New RasterCodecs() Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_SaveStream1.tif") ' Load the source file (make sure to load as 24 bits/pixel) Dim image As RasterImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1) Console.WriteLine("Loaded image has {0} bpp", image.BitsPerPixel) ' Create a stream for the destination file Dim fs As FileStream = File.Create(destFileName) ' Save it as 1 bpp TIF codecs.Save(image, fs, RasterImageFormat.Tif, 1) fs.Close() image.Dispose() ' Check if the image was saved correctly Dim info As CodecsImageInfo = codecs.GetInformation(destFileName, False) Console.WriteLine("Saved image has {0} bpp", info.BitsPerPixel) ' Clean up codecs.Dispose() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; using Leadtools.Svg; public void SaveStream1Example() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_SaveStream1.tif"); // Load the source file (make sure to load as 24 bits/pixel) RasterImage image = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1); Console.WriteLine("Loaded image has {0} bpp", image.BitsPerPixel); // Create a stream for the destination file FileStream fs = File.Create(destFileName); // Save it as 1 bpp TIF codecs.Save(image, fs, RasterImageFormat.Tif, 1); fs.Close(); image.Dispose(); // Check if the image was saved correctly CodecsImageInfo info = codecs.GetInformation(destFileName, false); Console.WriteLine("Saved image has {0} bpp", info.BitsPerPixel); // Clean up codecs.Dispose(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
using Leadtools; using Leadtools.Codecs; using Leadtools.Examples; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; using Leadtools.Windows.Media; public void SaveStream1Example(Stream inStreamCmp, Stream outStreamTif) { RasterCodecs codecs = new RasterCodecs(); // Load the source file (make sure to load as 24 bits/pixel) RasterImage image = codecs.Load(inStreamCmp, 24, CodecsLoadByteOrder.Bgr, 1, 1); Debug.WriteLine("Loaded image has {0} bpp", image.BitsPerPixel); // Save it as 1 bpp TIF codecs.Save(image, outStreamTif, RasterImageFormat.Tif, 1); image.Dispose(); // Check if the image was saved correctly CodecsImageInfo info = codecs.GetInformation(outStreamTif, false); Debug.WriteLine("Saved image has {0} bpp", info.BitsPerPixel); }
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Color Imports Leadtools.Windows.Media Public Sub SaveStream1Example(ByVal inStreamCmp As Stream, ByVal outStreamTif As Stream) Dim codecs As RasterCodecs = New RasterCodecs() ' Load the source file (make sure to load as 24 bits/pixel) Dim image As RasterImage = codecs.Load(inStreamCmp, 24, CodecsLoadByteOrder.Bgr, 1, 1) Debug.WriteLine("Loaded image has {0} bpp", image.BitsPerPixel) ' Save it as 1 bpp TIF codecs.Save(image, outStreamTif, RasterImageFormat.Tif, 1) image.Dispose() ' Check if the image was saved correctly Dim info As CodecsImageInfo = codecs.GetInformation(outStreamTif, False) Debug.WriteLine("Saved image has {0} bpp", info.BitsPerPixel) End Sub