←Select platform

RasterImageTypeConverter Constructor(RasterCodecs)

Summary
Initializes a new instance of the RasterImageTypeConverter class with a given RasterCodecs object.
Syntax
C#
C++/CLI
Python
public: 
RasterImageTypeConverter(  
   RasterCodecs^ codecs 
) 
__init__(self,codecs) # Overloaded constructor 

Parameters

codecs
The RasterCodecs object.

Remarks

NOTE: This topic is part of RasterCodecs Async support using the .NET System.ComponentMode.AsyncOperation model. For .NET async/await support this type/member is not used. Instead, refer to RasterCodecs Async Operations.

The image returned from the ConvertFrom method will have itsRasterImage.IsLoading property set to true since this method will load the image asynchronously. To get notified when the image has finished loading, create the RasterImageTypeConverter with your own RasterCodecs instance and subscribe to the RasterCodecs.LoadAsyncCompleted event before calling ConvertFrom as shown in the example of RasterImageTypeConverter.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.ImageProcessing.Core; 
 
public void RasterImageTypeConverterExample() 
{ 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
 
   // Construct the source URL to use the source file and load the image 
   Uri uri = new Uri(srcFileName); 
 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // Create a new instance of the RasterImageTypeConverter class 
   RasterImageTypeConverter rasterImageConverter = new RasterImageTypeConverter(codecs); 
 
   // We should be able to convert from a URL 
   Debug.Assert(rasterImageConverter.CanConvertFrom(uri.GetType())); 
 
   // Convert the image 
 
   // The return value from RasterImageTypeConverter.ConvertFrom might be an image that is 
   // still loading. So, we must subscribe to the RasterCodecs.LoadAsyncCompleteted 
   // event to obtain the finished image 
   codecs.LoadAsyncCompleted += new EventHandler<CodecsLoadAsyncCompletedEventArgs>(rasterImageTypeConverterExample_LoadAsyncCompleted); 
   object rasterImageObject = rasterImageConverter.ConvertFrom(uri); 
 
   // 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 rasterImageTypeConverterExample_LoadAsyncCompleted(object sender, CodecsLoadAsyncCompletedEventArgs e) 
{ 
   // Check if the user canceled or if we have errors 
   if (e.Cancelled) 
   { 
      Debug.WriteLine("Canceled by the user"); 
   } 
   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 {0} loaded OK, size: {1} by {2}", e.Uri, image.Width, image.Height); 
 
      image.Dispose(); 
   } 
 
   // Unsubscribe to the event and dispose the RasterCodecs object 
   RasterCodecs codecs = sender as RasterCodecs; 
   codecs.LoadAsyncCompleted -= new EventHandler<CodecsLoadAsyncCompletedEventArgs>(rasterImageTypeConverterExample_LoadAsyncCompleted); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Codecs Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.