LEADTOOLS Image File Support (Leadtools.Codecs assembly)
LEAD Technologies, Inc

LoadAsync(ILeadStream) Method

Example 





An Leadtools.ILeadStream containing the image data to load.
Loads the specified rectangle from the specified image stream using the specified options asynchronously. .NET support WinRT support
Syntax
public IAsyncOperation<RasterImage> LoadAsync( 
   ILeadStream stream
)
'Declaration
 
Public Overloads Function LoadAsync( _
   ByVal stream As ILeadStream _
) As IAsyncOperation(Of RasterImage)
'Usage
 
Dim instance As RasterCodecs
Dim stream As ILeadStream
Dim value As IAsyncOperation(Of RasterImage)
 
value = instance.LoadAsync(stream)
public IAsyncOperation<RasterImage> LoadAsync( 
   ILeadStream stream
)
 function Leadtools.Codecs.RasterCodecs.LoadAsync(ILeadStream)( 
   stream 
)
public:
IAsyncOperation<RasterImage^>^ LoadAsync( 
   ILeadStream^ stream
) 

Parameters

stream
An Leadtools.ILeadStream containing the image data to load.

Return Value

When this method completes, it returns the image as a Leadtools.RasterImage.
Remarks

LEADTOOLS will attempt to load corrupted files so you can see at least a portion of the image. For such images, the load methods succeed, but the 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 RasterCodecs class supports loading image files asynchronously using the LoadAsync methods. When calling any of these methods, the caller thread will not be blocked and the method will return instantly with an instance of Leadtools.RasterImage that is in a loading status (RasterImage.IsLoading set to true). Do not use the other properties of this object while the object is in loading status.

When the RasterCodecs object finishes loading the image, the various properties of the Leadtools.RasterImage will be populated with the image information and data and the RasterImage.IsLoading property will be set to false.

Do not poll the RasterImage.IsLoading property to whether the image has finished loading. Instead, subscribe to the IAsyncOperation.Completed event to get notification when the LoadAsync(String,LeadRect,Int32,CodecsLoadByteOrder,Int32,Int32,Object) operation has completed and whether any errors occurred.

When this method completes, it returns the image as a Leadtools.RasterImage.

Example
 
RasterCodecsExamples.prototype.LoadFile1Example = function ( )
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {

         var codecs = new RasterCodecs();
         var loadFile;
         var image;
         var image2;
         var info;
         var info2;
         var singlePageFileName = "Assets\\Image1.cmp";
         var multiPageFileName = "Assets\\Eye.gif";

         // Get the file information (we are interested in the number of pages)
         return Tools.AppInstallFolder().getFileAsync(singlePageFileName).then(function (loadFle) {
            loadFile = loadFle;
            return codecs.getInformationAsync(LeadStreamFactory.create(loadFile), true, 1)
         })
         .then(function (inf) {
            info = inf;
            console.info("Number of pages according to info: ", info.totalPages);

            // Load the image and verify that we loaded all the pages
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
         .then(function (img) {
            image = img;
            console.info("Number of pages loaded: ", image.pageCount);
            console.assert(image.pageCount === info.totalPages, "image.pageCount === info.totalPages");
            image.close();

            // Repeat for a multipage file
            return Tools.AppInstallFolder().getFileAsync(multiPageFileName)
         })
         .then(function (loadFile2) {
            loadFile = loadFile2;
            return codecs.getInformationAsync(LeadStreamFactory.create(loadFile2), true, 1)
         })
         .then(function (inf2) {
            info2 = inf2;
            console.info("Number of pages according to info: ", info2.totalPages);

            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
         .then(function (img2) {
            image2 = img2;
            console.info("Number of pages loaded: ", image2.pageCount);
            console.info(image2.pageCount == info2.totalPages);
            image.close();
            image2.close();
            // Clean up
            codecs.close();
         });
      }
   }
}
[TestMethod]
public async Task LoadFile1Example()
{
   RasterCodecs codecs = new RasterCodecs();
   string singlePageFileName = @"Assets\Image1.cmp";
   string multiPageFileName = @"Assets\Eye.gif";

   // Get the file information (we are interested in the number of pages)
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(singlePageFileName);
   CodecsImageInfo info = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), true, 1);
   Debug.WriteLine("Number of pages according to info: {0}", info.TotalPages);

   // Load the image and verify that we loaded all the pages
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
   Debug.WriteLine("Number of pages loaded: {0}", image.PageCount);
   Assert.IsTrue(image.PageCount == info.TotalPages);
   image.Dispose();

   // Repeat for a multipage file
   loadFile = await Tools.AppInstallFolder.GetFileAsync(multiPageFileName);
   info = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), true, 1);
   Debug.WriteLine("Number of pages according to info: {0}", info.TotalPages);

   image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
   Debug.WriteLine("Number of pages loaded: {0}", image.PageCount);
   Assert.IsTrue(image.PageCount == info.TotalPages);
   image.Dispose();

   // Clean up
   codecs.Dispose();
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RasterCodecs Class
RasterCodecs Members
Overload List
Loading and Saving Images
Loading and Saving Large Tiff Files
Speeding Up 1-Bit Documents
Fast File Info

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.