←Select platform

LoadAsync(RasterCodecs,ILeadStream,int) Method

Summary

Asynchronously loads the specified page from an image stream using default options.

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

Parameters

rasterCodecs

RasterCodecs object to perform the operation.

stream

A Stream containing the image data to load.

pageNumber

The 1-based page number.

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 a single page from 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.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
public async void LoadAsync2Example() 
{ 
   // 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 the specified page number from the PDF image in a remote URL 
   string address = @"https://demo.leadtools.com/images/pdf/leadtools.pdf"; 
   int pageNumber = 2; 
   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, pageNumber)) 
         { 
            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); 
         } 
      } 
   } 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
public void loadAsync2Example() throws URISyntaxException, IOException { 
   // Load the specified page number from the PDF image in a remote URL 
   String address = "https://demo.leadtools.com/images/pdf/leadtools.pdf"; 
   int pageNumber = 2; 
   URI uri = new URI(address); 
 
   RasterCodecs codecs = new RasterCodecs(); 
   // Create an ILeadStream object to the URI 
   ILeadStream leadStream = LeadStreamFactory.create(uri); 
   codecs.addLoadAsyncCompletedListener(new CodecsLoadAsyncCompletedListener() { 
 
      @Override 
      public void onLoadAsyncCompleted(CodecsLoadAsyncCompletedEvent e) { 
         RasterImage image = e.getImage(); 
         System.out.printf("Image loaded from %s :%n", uri); 
         System.out.println("Width: " + image.getImageWidth()); 
         System.out.println("Height: " + image.getImageHeight()); 
         System.out.println("BitsPerPixel: " + image.getBitsPerPixel()); 
         System.out.println("BytesPerLine: " + image.getBytesPerLine()); 
      } 
   }); 
 
   codecs.loadAsync(leadStream, pageNumber); 
   leadStream.close(); 
} 
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.