←Select platform

SaveAsync(RasterCodecs,RasterImage,ILeadStream,RasterImageFormat,int,int,int,int,CodecsSavePageMode) Method

Summary

Asynchronously saves one or more pages of a RasterImage to a LEAD stream in any of the supported compressed or uncompressed formats.

Syntax
C#

Parameters

rasterCodecs

RasterCodecs object to perform the operation.

image

The RasterImage object that holds the image data.

stream

The stream where the image data will be saved.

format

The output file format. For valid values, refer to

Summary of All Supported 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 File Formats. If bitsPerPixel is 0, the image will be stored using the closest bits per pixel value supported by that format. For example, if a file format supports 1-, 4-, and 24-bits per 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.

firstPage

1-based index of the first page in image to save.

lastPage

1-based index of the last page in image to save. Pass -1 to save from

firstPage to the last page in image.

firstSavePageNumber

1-based index of the first output page. If the output file already exists, then this

parameter lets you control which pages to overwrite and/or where to append the new pages.

pageMode

Determines how to handle the page when saving to multipage formats. The following values are possible:

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.

Return Value

A Task that represents the asynchronous operation.

Remarks

This topic is part of RasterCodecs support for .NET async/await support. Refer to RasterCodecs Async Operations for more information.

For general information on saving images using RasterCodecs, refer to Save.

Example
C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
 
public async Task<MemoryStream> LoadAsPng(Uri uri, int pageNumber) 
{ 
   // For .NET Framework: Add a reference to Leadtools.Async to get the async support as extension methods 
   // For .NET Standard: async support is included. 
 
   MemoryStream memoryStream = new MemoryStream(); 
 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      // Create an ILeadStream for the output file 
      using (ILeadStream inputLeadStream = await LeadStream.Factory.FromUri(uri)) 
      // ILeadStream for the output stream 
      using (ILeadStream outputLeadStream = LeadStream.Factory.FromStream(memoryStream)) 
      { 
         // Load the image 
         using (RasterImage image = await codecs.LoadAsync(inputLeadStream, pageNumber)) 
         { 
            // Save it to the output stream 
            await codecs.SaveAsync(image, outputLeadStream, RasterImageFormat.Png, 0); 
         } 
      } 
   } 
 
   return memoryStream; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Drawing 
Imports Leadtools.Svg 
 
Public Async Function LoadAsPng(uri As Uri, pageNumber As Integer) As Tasks.Task(Of Stream) 
   ' For .NET Framework: Add a reference To Leadtools.Async To Get the async support As extension methods 
   ' For .NET Standard Async support Is included. 
 
   Dim memoryStream As New MemoryStream() 
 
   Using codecs As New RasterCodecs() 
      ' Create an ILeadStream for the output file 
      Using inputLeadStream As ILeadStream = Await LeadStream.Factory.FromUri(uri) 
         ' ILeadStream for the output stream 
         Using outputLeadStream As ILeadStream = LeadStream.Factory.FromStream(memoryStream) 
            ' Load the image 
            Using image As RasterImage = Await codecs.LoadAsync(inputLeadStream, pageNumber) 
               ' Save it to the output stream 
               Await codecs.SaveAsync(image, outputLeadStream, RasterImageFormat.Png, 0) 
            End Using 
         End Using 
      End Using 
   End Using 
 
   Return memoryStream 
End Function 

Requirements

For .NET Framework: A reference to the Leadtools.Async.dll assembly is required to use this functionality.

For .NET Standard: This functionality is included in the Leadtools.Codecs.dll assembly.

Target Platforms

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

Leadtools.Codecs Assembly