Leadtools.Codecs Namespace > RasterCodecs Class > SaveAsync Method : SaveAsync(RasterImage,ILeadStream,RasterImageFormat,Int32,Int32,Int32,Int32,CodecsSavePageMode) Method |
Determines how to handle the page when saving to multipage formats. This can be one of the following:
Value | Meaning |
---|---|
CodecsSavePageMode.Append | Append the new page(s) to the end of the file. If the file does not exist, this option will create the file and add the pages to it. firstSavePageNumber is not used. |
CodecsSavePageMode.Insert | Insert the new page(s) at the index specified by firstSavePageNumber. |
CodecsSavePageMode.Replace | Replace the page(s) starting at the index specified by firstSavePageNumber. |
CodecsSavePageMode.Overwrite | Overwrite the page(s) starting at the index specified by firstSavePageNumber. |
public IAsyncAction SaveAsync( RasterImage image, ILeadStream stream, RasterImageFormat format, int bitsPerPixel, int firstPage, int lastPage, int firstSavePageNumber, CodecsSavePageMode pageMode )
'Declaration Public Overloads Function SaveAsync( _ ByVal image As RasterImage, _ ByVal stream As ILeadStream, _ ByVal format As RasterImageFormat, _ ByVal bitsPerPixel As Integer, _ ByVal firstPage As Integer, _ ByVal lastPage As Integer, _ ByVal firstSavePageNumber As Integer, _ ByVal pageMode As CodecsSavePageMode _ ) As IAsyncAction
'Usage Dim instance As RasterCodecs Dim image As RasterImage Dim stream As ILeadStream Dim format As RasterImageFormat Dim bitsPerPixel As Integer Dim firstPage As Integer Dim lastPage As Integer Dim firstSavePageNumber As Integer Dim pageMode As CodecsSavePageMode Dim value As IAsyncAction value = instance.SaveAsync(image, stream, format, bitsPerPixel, firstPage, lastPage, firstSavePageNumber, pageMode)
public IAsyncAction SaveAsync( RasterImage image, ILeadStream stream, RasterImageFormat format, int bitsPerPixel, int firstPage, int lastPage, int firstSavePageNumber, CodecsSavePageMode pageMode )
function Leadtools.Codecs.RasterCodecs.SaveAsync(RasterImage,ILeadStream,RasterImageFormat,Int32,Int32,Int32,Int32,CodecsSavePageMode)( image , stream , format , bitsPerPixel , firstPage , lastPage , firstSavePageNumber , pageMode )
public: IAsyncAction^ SaveAsync( RasterImage^ image, ILeadStream^ stream, RasterImageFormat format, int bitsPerPixel, int firstPage, int lastPage, int firstSavePageNumber, CodecsSavePageMode pageMode )
Determines how to handle the page when saving to multipage formats. This can be one of the following:
Value | Meaning |
---|---|
CodecsSavePageMode.Append | Append the new page(s) to the end of the file. If the file does not exist, this option will create the file and add the pages to it. firstSavePageNumber is not used. |
CodecsSavePageMode.Insert | Insert the new page(s) at the index specified by firstSavePageNumber. |
CodecsSavePageMode.Replace | Replace the page(s) starting at the index specified by firstSavePageNumber. |
CodecsSavePageMode.Overwrite | Overwrite the page(s) starting at the index specified by firstSavePageNumber. |
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 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.
RasterCodecsExamples.prototype.SaveFile2Example = function () { Tools.SetLicense(); with (Leadtools) { with (Leadtools.Codecs) { var codecs = new RasterCodecs(); var destFileName = "Image1_SaveFile2.tif"; var image; var pageCount = 4; var files = []; var saveFile; // Create a multi-page image for testing purposes for (var i = 1; i <= 4; i++) { files[i] = "Assets\\OCR" + i + ".tif"; } var promises = files.map(function (srcFileName) { return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) { return codecs.loadAsync(LeadStreamFactory.create(loadFile)) }) .then(function (pageImage) { if (image == null) image = pageImage; else { image.addPage(pageImage); pageImage.close(); } }); }); return WinJS.Promise.join(promises).then(function () { // Save all the pages to the file // The file should have 4 pages now: 1, 2, 3, 4 return Tools.AppLocalFolder().createFileAsync(destFileName) }) .then(function (saveFileX) { saveFile = saveFileX; return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 1, 1, pageCount, 1, CodecsSavePageMode.overwrite) }) .then(function () { image.close(); // Load the 3rd page and insert it as the second // The file should have 5 pages now: 1, 3, 2, 3, 4 return codecs.loadAsync(LeadStreamFactory.create(saveFile), 0, CodecsLoadByteOrder.bgrOrGray, 3, 3) }) .then(function (img) { image = img; return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 1, 1, 1, 2, CodecsSavePageMode.insert) }) .then(function () { image.close(); // Load the last page, and insert it as the first // The file should have 5 pages now: 4, 1, 3, 2, 3, 4 return codecs.loadAsync(LeadStreamFactory.create(saveFile), 0, CodecsLoadByteOrder.bgrOrGray, 5, 5) }) .then(function (img) { image = img; return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 1, 1, 1, 1, CodecsSavePageMode.insert) }) .then(function () { image.close(); // Replace the 5th page with the 2nd // The file should have 5 pages now: 4, 1, 3, 2, 1, 4 return codecs.loadAsync(LeadStreamFactory.create(saveFile), 0, CodecsLoadByteOrder.bgrOrGray, 2, 2) }) .then(function (img) { image = img; return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 1, 1, 1, 5, CodecsSavePageMode.replace) }) .then(function () { image.close(); // Delete the 2nd and 6th pages // The file should have 5 pages now: 4, 3, 2, 1 return codecs.deletePageAsync(LeadStreamFactory.create(saveFile), 2) }) .then(function () { // Notice, -1 because we already deleted a page, so 6th page is not 5th return codecs.deletePageAsync(LeadStreamFactory.create(saveFile), 6 - 1) }) .then(function () { // Clean up codecs.close(); }); } } }
[TestMethod] public async Task SaveFile2Example() { RasterCodecs codecs = new RasterCodecs(); string destFileName = @"Image1_SaveFile2.tif"; const int pageCount = 4; // Create a multi-page image for testing purposes RasterImage image = null; for (int i = 1; i <= 4; i++) { string srcFileName = String.Format(@"Assets\OCR{0}.tif", i); StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); RasterImage pageImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)); if (image == null) image = pageImage; else { image.AddPage(pageImage); pageImage.Dispose(); } } // Save all the pages to the file // The file should have 4 pages now: 1, 2, 3, 4 StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1, 1, pageCount, 1, CodecsSavePageMode.Overwrite); image.Dispose(); // Load the 3rd page and insert it as the second // The file should have 5 pages now: 1, 3, 2, 3, 4 image = await codecs.LoadAsync(LeadStreamFactory.Create(saveFile), 0, CodecsLoadByteOrder.BgrOrGray, 3, 3); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1, 1, 1, 2, CodecsSavePageMode.Insert); image.Dispose(); // Load the last page, and insert it as the first // The file should have 5 pages now: 4, 1, 3, 2, 3, 4 image = await codecs.LoadAsync(LeadStreamFactory.Create(saveFile), 0, CodecsLoadByteOrder.BgrOrGray, 5, 5); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1, 1, 1, 1, CodecsSavePageMode.Insert); image.Dispose(); // Replace the 5th page with the 2nd // The file should have 5 pages now: 4, 1, 3, 2, 1, 4 image = await codecs.LoadAsync(LeadStreamFactory.Create(saveFile), 0, CodecsLoadByteOrder.BgrOrGray, 2, 2); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1, 1, 1, 5, CodecsSavePageMode.Replace); image.Dispose(); // Delete the 2nd and 6th pages // The file should have 5 pages now: 4, 3, 2, 1 await codecs.DeletePageAsync(LeadStreamFactory.Create(saveFile), 2); // Notice, -1 because we already deleted a page, so 6th page is not 5th await codecs.DeletePageAsync(LeadStreamFactory.Create(saveFile), 6 - 1); // Clean up codecs.Dispose(); }
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