LoadAsync(string,int,object) Method (original) (raw)

Summary

Loads the specified page from an image file using default options asynchronously.

Syntax

C#

Objective-C

C++/CLI

Python

- (void)loadFileAsync:(NSString *)file pageNumber:(NSInteger)_pageNumber_ completion:(void (^)(LTRasterImage * __nullable image, NSError * __nullable error))completion

Parameters

fileName
A String containing the name of the image file to load.

pageNumber
The 1-based page number.

userState
A user-defined object that is passed to the method invoked when the asynchronous operation completes.

Return Value

The RasterImage object that this method loads. See remarks for the usage of this object.

Example

This example will query the number of pages from a file and then load them.

using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Color; using Leadtools.Svg; class LoadPagesFromFileAsyncTestData { public int PageCount; public int PageNumber; } private static void LoadPagesFromFileAsyncTest(string fileName) { // Create a new RasterCodecs instance, we will dispose it when the images finish loading RasterCodecs rasterCodecs = new RasterCodecs(); // Create the data LoadPagesFromFileAsyncTestData data = new LoadPagesFromFileAsyncTestData(); // Get the number of pages data.PageCount = rasterCodecs.GetTotalPages(fileName); Debug.WriteLine("Number of pages in the file is {0}", data.PageCount); // Load all pages asynchrounsly data.PageNumber = 1; // Start with the first page, then load next when operation finishes rasterCodecs.LoadAsyncCompleted += new EventHandler<CodecsLoadAsyncCompletedEventArgs>(rasterCodecs_LoadAsyncCompleted); rasterCodecs.LoadAsync(fileName, data.PageNumber, data); } private static void rasterCodecs_LoadAsyncCompleted(object sender, CodecsLoadAsyncCompletedEventArgs e) { // A page is loaded, show info LoadPagesFromFileAsyncTestData data = e.UserState as LoadPagesFromFileAsyncTestData; Debug.WriteLine("Page {0} loaded", data.PageNumber); // If there is an error, show it if (e.Error != null) Debug.WriteLine("Error {0}", e.Error.Message); // Dispose the image if (e.Image != null) e.Image.Dispose(); // Get the raster codecs instance RasterCodecs rasterCodecs = sender as RasterCodecs; if (data.PageNumber < data.PageCount) { // Load next Debug.WriteLine("Load next"); data.PageNumber++; rasterCodecs.LoadAsync(e.FileName, data.PageNumber, data); } else { // Finished loading, clean up Debug.WriteLine("Finished"); rasterCodecs.LoadAsyncCompleted -= new EventHandler<CodecsLoadAsyncCompletedEventArgs>(rasterCodecs_LoadAsyncCompleted); rasterCodecs.Dispose(); } }

Leadtools.Codecs Assembly

CompactFile(Stream,Stream,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method

CompactFile(Stream,Stream,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method

CompactFile(string,string,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method

CompactFile(string,string,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method

StartCompress(int,int,int,RasterByteOrder,RasterViewPerspective,int,byte[],int,int,CodecsCompression,CodecsCompressDataCallback) Method