Loads the specified page from an image file using default options asynchronously.
public Leadtools.RasterImage LoadAsync(string fileName,int pageNumber,object userState)
Public Overloads Function LoadAsync( _ByVal fileName As String, _ByVal pageNumber As Integer, _ByVal userState As Object _) As Leadtools.RasterImage
public Leadtools.RasterImage LoadAsync(string fileName,int pageNumber,object userState)
- (void)loadFileAsync:(NSString *)filepageNumber:(NSInteger)pageNumbercompletion:(void (^)(LTRasterImage * nullable image, NSError * nullable error))completion
function Leadtools.Codecs.RasterCodecs.LoadAsync(String,Int32,Object)(fileName ,pageNumber ,userState)
public:Leadtools.RasterImage^ LoadAsync(String^ fileName,int pageNumber,Object^ userState)
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.
The RasterImage object that this method loads. See remarks for the usage of this object.
The file can be in any supported image file format and bits per pixel, whether compressed or uncompressed.
This method will load a single page from 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 file.
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 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 RasterImage that is in a loading status (RasterImage.IsLoading set to true). You should 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 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 determine whether the image has finished loading. Instead, subscribe to the LoadAsyncCompleted event to get notification when the LoadAsync operation has completed and whether any errors occurred.
The LoadAsyncCompleted event data will also contain the same object returned from LoadAsync so you do not have to keep the original object in your application.
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;using LeadtoolsExamples.Common;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 loadingRasterCodecs rasterCodecs = new RasterCodecs();// Create the dataLoadPagesFromFileAsyncTestData data = new LoadPagesFromFileAsyncTestData();// Get the number of pagesdata.PageCount = rasterCodecs.GetTotalPages(fileName);Console.WriteLine("Number of pages in the file is {0}", data.PageCount);// Load all pages asynchrounslydata.PageNumber = 1;// Start with the first page, then load next when operation finishesrasterCodecs.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 infoLoadPagesFromFileAsyncTestData data = e.UserState as LoadPagesFromFileAsyncTestData;Console.WriteLine("Page {0} loaded", data.PageNumber);// If there is an error, show itif (e.Error != null)Console.WriteLine("Error {0}", e.Error.Message);// Dispose the imageif (e.Image != null)e.Image.Dispose();// Get the raster codecs instanceRasterCodecs rasterCodecs = sender as RasterCodecs;if (data.PageNumber < data.PageCount){// Load nextConsole.WriteLine("Load next");data.PageNumber++;rasterCodecs.LoadAsync(e.FileName, data.PageNumber, data);}else{// Finished loading, clean upConsole.WriteLine("Finished");rasterCodecs.LoadAsyncCompleted -= new EventHandler<CodecsLoadAsyncCompletedEventArgs>(rasterCodecs_LoadAsyncCompleted);rasterCodecs.Dispose();}}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorImports Leadtools.DrawingImports Leadtools.SvgClass LoadPagesFromFileAsyncTestDataPublic PageCount As IntegerPublic PageNumber As IntegerEnd ClassPrivate Shared Sub LoadPagesFromFileAsyncTest(fileName As String)' Create a new RasterCodecs instance, we will dispose it when the images finish loadingDim rasterCodecs As New RasterCodecs()' Create the dataDim data As New LoadPagesFromFileAsyncTestData()' Get the number of pagesdata.PageCount = rasterCodecs.GetTotalPages(fileName)Console.WriteLine("Number of pages in the file is {0}", data.PageCount)' Load all pages asynchrounslydata.PageNumber = 1' Start with the first page, then load next when operation finishesAddHandler rasterCodecs.LoadAsyncCompleted, AddressOf rasterCodecs_LoadAsyncCompletedrasterCodecs.LoadAsync(fileName, data.PageNumber, data)End SubPrivate Shared Sub rasterCodecs_LoadAsyncCompleted(sender As Object, e As CodecsLoadAsyncCompletedEventArgs)' A page is loaded, show infoDim data As LoadPagesFromFileAsyncTestData = CType(e.UserState, LoadPagesFromFileAsyncTestData)Console.WriteLine("Page {0} loaded", data.PageNumber)' If there is an error, show itIf Not IsNothing(e.Error) ThenConsole.WriteLine("Error {0}", e.Error.Message)End If' Dispose the imageIf Not IsNothing(e.Image) Thene.Image.Dispose()End If' Get the raster codecs instanceDim rasterCodecs As RasterCodecs = CType(sender, RasterCodecs)If data.PageNumber < data.PageCount Then' Load nextConsole.WriteLine("Load next")data.PageNumber = data.PageNumber + 1rasterCodecs.LoadAsync(e.FileName, data.PageNumber, data)Else' Finished loading, clean upConsole.WriteLine("Finished")RemoveHandler rasterCodecs.LoadAsyncCompleted, AddressOf rasterCodecs_LoadAsyncCompletedrasterCodecs.Dispose()End IfEnd Sub
|
Products |
Support |
Feedback: LoadAsync(String,Int32,Object) Method - Leadtools.Codecs |
Introduction |
Help Version 19.0.2017.6.16
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.