Attempts to convert a specified object to an instance of RasterImage.
public override object ConvertFrom(ITypeDescriptorContext context,CultureInfo culture,object value)
public:Object^ ConvertFrom(ITypeDescriptorContext^ context,CultureInfo^ culture,Object^ value) override
context
Type context information used for conversion.
culture
Cultural information that is respected during conversion.
value
The object being converted.
A new instance of RasterImage.
The ConvertFrom method will try to convert the object passed into the value parameter to a valid RasterImage object. For more information, refer to RasterImageTypeConverter.
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 imageUri uri = new Uri(srcFileName);RasterCodecs codecs = new RasterCodecs();// Create a new instance of the RasterImageTypeConverter classRasterImageTypeConverter rasterImageConverter = new RasterImageTypeConverter(codecs);// We should be able to convert from a URLDebug.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 imagecodecs.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 errorsif (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 imageRasterImage 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 objectRasterCodecs 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";}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
