LoadAsync(Stream,object) Method (original) (raw)
Summary
Loads the specified image stream using default options asynchronously.
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (void)loadStreamAsync:(LTLeadStream *)_stream_
completion:(void (^)(LTRasterImage * __nullable image, NSError * __nullable error))completion
Parameters
stream
A Stream containing the image data to load.
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
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;
using Leadtools.Svg;
public void LoadAsyncStream1Example()
{
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
RasterCodecs codecs = new RasterCodecs();
// Now load the image asynchronously
codecs.LoadAsyncCompleted += new EventHandler<CodecsLoadAsyncCompletedEventArgs>(LoadAsyncStream1Example_LoadAsyncCompleted);
Stream stream = File.OpenRead(srcFileName);
object rasterImageObject = codecs.LoadAsync(stream, null);
// Notice that the returned rasterImageObject is a RasterImage with IsLoading set to true at this point
// The IsLoading will be false (and hence, the object will be usable) when the LoadAsyncCompleteted
// fires.
}
private void LoadAsyncStream1Example_LoadAsyncCompleted(object sender, CodecsLoadAsyncCompletedEventArgs e)
{
if (e.Cancelled)
{
Debug.WriteLine("User canceled");
}
else if (e.Error != null)
{
Debug.WriteLine("Error: " + e.Error.Message);
}
else
{
// Everything is OK, get the image
RasterImage image = e.Image;
Debug.WriteLine("Image at loaded OK, size: {0} by {1}", image.Width, image.Height);
image.Dispose();
}
// We should close the stream here
e.Stream.Dispose();
// Unsubscribe to the event and dispose the RasterCodecs object
RasterCodecs codecs = sender as RasterCodecs;
codecs.LoadAsyncCompleted -= new EventHandler<CodecsLoadAsyncCompletedEventArgs>(LoadAsyncStream1Example_LoadAsyncCompleted);
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}
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