LEADTOOLS Image File Support (Leadtools.Codecs assembly)
LEAD Technologies, Inc

SaveAsync(RasterImage,ILeadStream,RasterImageFormat,Int32) Method

Example 





The Leadtools.RasterImage object that holds the image data.
An Leadtools.ILeadStream where the image data will be saved.
The output file format. For valid values, Summary of All Supported Image File Formats.
Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Summary of All Supported Image File Formats. If bitsPerPixel is 0, the image will be stored using the closet bits/pixel value supported by that format. For example, if a file format supports 1, 4, and 24 bits/pixel, and RasterImage.BitsPerPixel is 5, the file will be stored as 24 bit. Likewise, if RasterImage.BitsPerPixel is 2, the file will be stored as 4 bit.
Saves a Leadtools.RasterImage to a stream in any of the supported compressed or uncompressed formats. .NET support WinRT support
Syntax
public IAsyncAction SaveAsync( 
   RasterImage image,
   ILeadStream stream,
   RasterImageFormat format,
   int bitsPerPixel
)
'Declaration
 
Public Overloads Function SaveAsync( _
   ByVal image As RasterImage, _
   ByVal stream As ILeadStream, _
   ByVal format As RasterImageFormat, _
   ByVal bitsPerPixel As Integer _
) As IAsyncAction
'Usage
 
Dim instance As RasterCodecs
Dim image As RasterImage
Dim stream As ILeadStream
Dim format As RasterImageFormat
Dim bitsPerPixel As Integer
Dim value As IAsyncAction
 
value = instance.SaveAsync(image, stream, format, bitsPerPixel)
public IAsyncAction SaveAsync( 
   RasterImage image,
   ILeadStream stream,
   RasterImageFormat format,
   int bitsPerPixel
)
 function Leadtools.Codecs.RasterCodecs.SaveAsync(RasterImage,ILeadStream,RasterImageFormat,Int32)( 
   image ,
   stream ,
   format ,
   bitsPerPixel 
)
public:
IAsyncAction^ SaveAsync( 
   RasterImage^ image,
   ILeadStream^ stream,
   RasterImageFormat format,
   int bitsPerPixel
) 

Parameters

image
The Leadtools.RasterImage object that holds the image data.
stream
An Leadtools.ILeadStream where the image data will be saved.
format
The output file format. For valid values, Summary of All Supported Image File Formats.
bitsPerPixel
Resulting file's pixel depth. Note that not all bits per pixel are available to all file formats. For valid values, refer to Summary of All Supported Image File Formats. If bitsPerPixel is 0, the image will be stored using the closet bits/pixel value supported by that format. For example, if a file format supports 1, 4, and 24 bits/pixel, and RasterImage.BitsPerPixel is 5, the file will be stored as 24 bit. Likewise, if RasterImage.BitsPerPixel is 2, the file will be stored as 4 bit.

Return Value

An asynchronous save operation on a RasterCodecs object.
Remarks

If the output file format supports multipage 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 Medical 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 Leadtools.ImageProcessing.Core.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 to 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 recommended when converting colored images containing text when performing document processing such as OCR or 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.

Example
 
RasterCodecsExamples.prototype.SaveFile1Example = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();
         var image;
         var srcFileName = "Assets\\Image1.cmp";
         var destFileName = "Image1_SaveFile1.tif";
         var saveFile;
         // Load the source file (make sure to load as 24 bits/pixel)
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile), 24, CodecsLoadByteOrder.bgr, 1, 1)
         })
            .then(function (img) {
               image = img;
               console.info("Loaded image has ", image.bitsPerPixel, " bpp");

               // Save it as 1 bpp TIF
               return Tools.AppLocalFolder().createFileAsync(destFileName)
            })
            .then(function (saveFileX) {
               saveFile = saveFileX;
               return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 1)
            })
            .then(function () {
               image.close();
               // Check if the image was saved correctly
               return codecs.getInformationAsync(LeadStreamFactory.create(saveFile), false, 1)
            })
            .then(function (info) {
               console.info("Saved image has ", info.bitsPerPixel, " bpp");

               // Clean up
               codecs.close();
            });
      }
   }
}
[TestMethod]
public async Task SaveFile1Example()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   string destFileName = @"Image1_SaveFile1.tif";

   // Load the source file (make sure to load as 24 bits/pixel)
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 24, CodecsLoadByteOrder.Bgr, 1, 1);
   Debug.WriteLine("Loaded image has {0} bpp", image.BitsPerPixel);

   // Save it as 1 bpp TIF
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1);
   image.Dispose();

   // Check if the image was saved correctly
   CodecsImageInfo info = await codecs.GetInformationAsync(LeadStreamFactory.Create(saveFile), false, 1);
   Debug.WriteLine("Saved image has {0} bpp", info.BitsPerPixel);

   // Clean up
   codecs.Dispose();
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RasterCodecs Class
RasterCodecs Members
Overload List
Loading and Saving Images
Loading and Saving Large Tiff Files
Speeding Up 1-Bit Documents
Working with Markers
Fast File Info

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.