←Select platform

LoadAsync(RasterCodecs,ILeadStream) Method

Summary

Asynchronously loads the specified image stream using default options.

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

Parameters

rasterCodecs

RasterCodecs object to perform the operation.

stream

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.

Remarks

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 multi-page 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 Image 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).

Example
C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
using LeadtoolsExamples.Common; 
 
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)) 
         { 
            Console.WriteLine("Image loaded from : {0}", uri); 
            Console.WriteLine("Width: {0}", image.ImageWidth); 
            Console.WriteLine("Height: {0}", image.ImageHeight); 
            Console.WriteLine("BitsPerPixel: {0}", image.BitsPerPixel); 
            Console.WriteLine("BytesPerLine: {0}", image.BytesPerLine); 
         } 
      } 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Drawing 
Imports Leadtools.Svg 
 
Public Async Sub 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 
   Dim address As String = "https://demo.leadtools.com/images/tiff/ocr1.tif" 
   Dim uri As New Uri(address) 
 
   Dim codecs As New RasterCodecs() 
   ' Create an ILeadStream object to the URI 
   Using stream As ILeadStream = Await LeadStream.Factory.FromUri(uri) 
      Using image As RasterImage = Await codecs.LoadAsync(stream) 
         Console.WriteLine("Image loaded from : {0}", uri) 
         Console.WriteLine("Width: {0}", image.ImageWidth) 
         Console.WriteLine("Height: {0}", image.ImageHeight) 
         Console.WriteLine("BitsPerPixel: {0}", image.BitsPerPixel) 
         Console.WriteLine("BytesPerLine: {0}", image.BytesPerLine) 
      End Using 
   End Using 
End Sub 

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

Leadtools.Codecs Assembly