←Select platform

LoadAsync(RasterCodecs,ILeadStream) Method


Asynchronously loads the specified image stream using default options.

[AsyncStateMachineAttribute(this System.Type)] 
public static Task<RasterImage> LoadAsync( 
   this RasterCodecs rasterCodecs, 
   ILeadStream stream 



RasterCodecs object to perform the operation.


A Stream containing the image data to load.

Return Value

A Task that represents the asynchronous operation. TResult: The RasterImage object that this method loads. See remarks for the usage of this object.


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

The stream can point to any supported image file format and bits per pixel, whether compressed or uncompressed.

This method will load all the pages in a multipage file. The resulting image will have the same bits/pixel and color order value of the image as it was stored in the stream.

LEADTOOLS will attempt to load corrupted files so you can see at least a portion of the image. For these images, the load methods succeed, but LoadStatus will return an error code.

Use the CodecsLoadOptions class to set up other load option parameters before calling this method.

Support for 12 and 16-bit grayscale images is only available in the Document/Medical Imaging editions.

For supported formats, refer to Summary of All Supported File Formats.

LEADTOOLS loads all PDF files as Raster PDF uncompressed RasterImageFormat.RasPdf, regardless of the compression and color space used when saving the file.

The CodecsLoadOptions.AllPages property controls whether RasterCodecs will try to load all pages or just the first page if the image data contains multiple pages. To load a single page, use LoadAsync(ILeadStream stream, int pageNumber).

using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
public async void LoadAsync1Example() 
   // For .NET Framework: Add a reference to Leadtools.Async to get the async support as extension methods 
   // For .NET Standard: async support is included. 
   // Load a TIF image from a remote URL 
   string address = @"https://demo.leadtools.com/images/tiff/ocr1.tif"; 
   Uri uri = new Uri(address); 
   using (RasterCodecs codecs = new RasterCodecs()) 
      // Create an ILeadStream object to the URI 
      using (ILeadStream leadStream = await LeadStream.Factory.FromUri(uri)) 
         using (RasterImage image = await codecs.LoadAsync(leadStream)) 
            Debug.WriteLine("Image loaded from : {0}", uri); 
            Debug.WriteLine("Width: {0}", image.ImageWidth); 
            Debug.WriteLine("Height: {0}", image.ImageHeight); 
            Debug.WriteLine("BitsPerPixel: {0}", image.BitsPerPixel); 
            Debug.WriteLine("BytesPerLine: {0}", image.BytesPerLine); 

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 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly

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