←Select platform

GetInformationAsync(string,bool,int,object) Method

Summary
Gets the image information from a disk file asynchronously.
语法
C#
VB
Objective-C
C++
public代码csImageInfoGetInformationAsync(stringfileName,booltotalPages,intpageNumber,objectuserState)
PublicOverloadsFunctionGetInformationAsync( _ByValfileNameAsString, _ByValtotalPagesAsBoolean, _ByValpageNumberAsInteger, _ByValuserStateAsObject_)As代码csImageInfo
- (void)imageInformationForFileAsync:(NSString *)filetotalPages:(BOOL)totalPagespageNumber:(NSInteger)pageNumbercompletion:(void(^)(LTCodecsImageInfo * __nullable info, NSError * __nullable error))completion
public:代码csImageInfo^GetInformationAsync(String^fileName,booltotalPages,intpageNumber,Object^userState)

Parameters

fileName
String containing the input file name to query.

totalPages
trueto query the file for total number of pages;false, otherwise.

pageNumber
The page number to query. Pass 1 for the first page (default).

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

Return Value

A代码csImageInfoobject that contains the information about the specified image. See remarks about the usage of this object.

Remarks

NOTE: This topic is part ofRasterCodecsAsync support using the .NETSystem.ComponentMode.AsyncOperationmodel. For .NETasync/await, useTask GetInformationAsync(ILeadStream stream, bool totalPages, int pageNumber).

Specifying true fortotalPagescan cause the process to be slow for files with large number of pages.

TheRasterCodecsclass supports getting information on image files asynchronously using theGetInformationAsyncmethods. When calling any of these methods, the caller thread will not be blocked and the method will return instantly with an instance代码csImageInfothat is in a loading status (代码csImageInfo.IsLoadingset totrue). You should not use the other properties of this object while the object is in loading status.

When theRasterCodecsobject finishes getting the information about the file, the various properties of the代码csImageInfowill be populated with the image file information and the代码csImageInfo.IsLoadingproperty will be set tofalse.

It is recommended that you do not poll for the代码csImageInfo.IsLoadingproperty to determine whether the image information has been collected. Instead, subscribe to theGetInformationAsyncCompleted事件时得到通知GetInformationAsyncoperation is completed and whether any errors occurred.

TheGetInformationAsyncCompletedevent data will also contain the same object returned fromGetInformationAsyncso you do not have to keep the original object in your application.userStatewill be passed to the CodecsGetInformationAsyncCompletedEventArgs.UserState member of theGetInformationAsyncCompletedevent data.

Example
C#
usingLeadtools;usingLeadtools.Codecs;usingLeadtools.ImageProcessing;usingLeadtools.ImageProcessing.Color;usingLeadtools.Svg;publicvoidGetInformationAsyncFileExample(){stringsrcFileName = Path.Combine(LEAD_VARS.ImagesDir,"Image1.cmp");RasterCodecs codecs =newRasterCodecs();// Now get information about the file asynchronouslycodecs.GetInformationAsyncCompleted +=newEventHandler(GetInformationAsyncFileExample_GetInformationAsyncCompleted);objectimageInfoObject = codecs.GetInformationAsync(srcFileName,true, 1,null);// Notice that the returned imageInfoObject is a CodecsImageInfo with IsLoading set to true at this point// The IsLoading will be false (and hence, the object will be usable) when the GetInformationAsyncCompleted// fires.}privatevoidGetInformationAsyncFileExample_GetInformationAsyncCompleted(objectsender, CodecsGetInformationAsyncCompletedEventArgs e){if(e.Cancelled){Console.WriteLine("User canceled");}elseif(e.Error !=null){Console.WriteLine("Error: "+ e.Error.Message);}else{// Get the image info代码csImageInfo info = e.Info;Console.WriteLine("Image info obtainted asynchronously:\n{0}", info.ToString());info.Dispose();}// Unsubscribe to the event and dispose the RasterCodecs objectRasterCodecs codecs = senderasRasterCodecs;codecs.GetInformationAsyncCompleted -=newEventHandler(GetInformationAsyncFileExample_GetInformationAsyncCompleted);codecs.Dispose();}staticclassLEAD_VARS{publicconststringImagesDir =@"C:\LEADTOOLS21\Resources\Images";}
Requirements

Target Platforms

Leadtools.Codecs Assembly
188金宝搏的网址客服|Support|Contact Us|Intellectual Property Notices
© 1991-2021LEAD Technologies, Inc.All Rights Reserved.