←Select platform

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

Summary

Asynchronously saves 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.

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#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public async Task<MemoryStream> LoadAsPng(string fileName) 
{ 
   // 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 = LeadStream.Factory.OpenFile(fileName)) 
      // ILeadStream for the output stream 
      using (ILeadStream outputLeadStream = LeadStream.Factory.FromStream(memoryStream)) 
      { 
         // Load the image 
         using (RasterImage image = await codecs.LoadAsync(inputLeadStream, 1)) 
         { 
            // Save it to the output stream 
            await codecs.SaveAsync(image, outputLeadStream, RasterImageFormat.Png, 0); 
         } 
      } 
   } 
 
   return memoryStream; 
} 
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 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.