Leadtools.Codecs Namespace : RasterImageTypeConverter Class |
public class RasterImageTypeConverter : System.ComponentModel.TypeConverter
'Declaration Public Class RasterImageTypeConverter Inherits System.ComponentModel.TypeConverter
'Usage Dim instance As RasterImageTypeConverter
public sealed class RasterImageTypeConverter : System.ComponentModel.TypeConverter
function Leadtools.Codecs.RasterImageTypeConverter()
public ref class RasterImageTypeConverter : public System.ComponentModel.TypeConverter
This class derives from the standard .NET System.ComponentModel.TypeConverter class to provides functionality for converting Leadtools.RasterImage objects from other data types.
The following data types are supported:
The CanConvertFrom(ITypeDescriptorContext,Type) method will return true if any of the supported object types is passed into the sourceType parameter. However, this does not mean that the conversion operation will succeed, this depends on whether the data contains a valid image that LEADTOOLS can load.
The ConvertFrom(ITypeDescriptorContext,CultureInfo,Object) method will try to convert the object passed into the value parameter to a valid Leadtools.RasterImage object.
For System.Uri and System.String source objects, LEADTOOLS supports optional extra parameters passed as standard HTML query string to fine tune the loading of Leadtools.RasterImage objects. The following table lists these parameters:
Parameter | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LeadBitsPerPixel |
Resulting image pixel depth. This should be a string representation of an integer. Valid values are:
|
||||||||||||||||||
LeadOrder |
Color order for 16-, 24-, 32-, 48-, and 64-bit images. If the resulting image is less than 16 bits per pixel, this will have no effect since palletized images have no order. This must be one of the following string values:
|
||||||||||||||||||
LeadFirstPage |
A string that contains an integer representation of the 1-based index of the first page to load. |
||||||||||||||||||
LeadLastPage |
A string that contains an integer representation of the 1-based index of last page to load. Must be greater than or equal to "LeadFirstPage" if specified. |
||||||||||||||||||
LeadUseWriteableBitmap |
For Silverlight only: a string that contains a boolean representation of a value that will be used to set CodecsLoadOptions.UseWriteableBitmap. If this is omitted, false will be used. If you add this parameter with a true value, then the resulting Leadtools.RasterImage will be loaded with a "WriteableBitmap" as the backend data. Refer to CodecsLoadOptions.UseWriteableBitmap for more information. |
||||||||||||||||||
LeadUseNativeLoad |
For Silverlight only: a string that contains a boolean representation of a value that will be used to set CodecsLoadOptions.UseNativeLoad. If this is omitted, false will be used. If you add this parameter with a true value, then the resulting Leadtools.RasterImage will be loaded with the native filter codecs instead of LEADTOOLS. Refer to CodecsLoadOptions.UseNativeLoad for more information. |
All these parameters are optional and should be passed as a standard HTML query string. The order is not important. Here are a few examples of valid strings:
// Load all the pages in the TIF file hosted at an HTTP URL http://tempuri.org/MyImage.tif // Load the first page only of the multi-page TIF file hosted at an HTTP URL http://tempuri.org/MyImage.tif?LeadFirstPage=1&LeadLastPage=1 // Load the second and third page of the multi-page TIF file hosted at an HTTP URL as 24 bits/pixel with RGB color order http://tempuri.org/MyImage.tif?LeadBitsPerPixel=24&LeadOrder=Rgb&LeadFirstPage=2&LeadLastPage=3 // Load all the pages in the TIF file hosted at an FTP site ftp://tempuri.org/MyImage.tif // Load all the pages in the TIF file in a disk file C:\Dir\MyImage.tif file:://C:/Dir/MyImage.tif file:://myserver/MyImage.tif // Load the second and third page of the multi-page TIF file in a disk file as 24 bits/pixel with RGB color order C:\Dir\MyImage\MyImage.tif?LeadBitsPerPixel=24&LeadOrder=Rgb&LeadFirstPage=2&LeadLastPage=3The RasterImageTypeConverter is also used when loading a resource image from XAML as a Leadtools.RasterImage. Here are a few example:
// Load all the pages in the TIF file set as resource "MyImage.tif" // Load the first page only of the multi-page TIF file set as a resource "MyImage.tif?LeadFirstPage=1&LeadLastPage=1" // Load the second and third page of the multi-page TIF file set as a resource as 24 bits/pixel with RGB color order "MyImage.tif?LeadBitsPerPixel=24&LeadOrder=Rgb&LeadFirstPage=2&LeadLastPage=3" // Load the second and third page of the multi-page TIF file set as a resource as 24 bits/pixel with RGB color order "MyImage.tif?LeadBitsPerPixel=24&LeadOrder=Rgb&LeadFirstPage=2&LeadLastPage=3" // Silverlight only: Load the image and set it as a WriteableBitmap in a RasterImage "MyImage.tif?LeadUseWriteableBitmap=True" // Silverlight only: Load the PNG image using Silverlight and set it as a WriteableBitmap in a RasterImage "MyImage.tif?LeadUseWriteableBitmap=True&LeadUseNativeLoad=True"
Query string are not supported for System.String and an array of System.Byte data types.
The LEADTOOLS WPF and Silverlight controls use the RasterImageTypeConverter to load a Leadtools.RasterImage from a XAML file.
The image returned from the ConvertFrom(ITypeDescriptorContext,CultureInfo,Object) method will have its RasterImage.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(ITypeDescriptorContext,CultureInfo,Object) as show in the example below.
Public Sub RasterImageTypeConverterExample() Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif") ' Construct the source URL to use the source file and load the image Dim uri As New Uri(srcFileName) Dim codecs As New RasterCodecs() ' Create a new instance of the RasterImageTypeConverter class Dim rasterImageConverter As 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 AddHandler codecs.LoadAsyncCompleted, AddressOf rasterImageTypeConverterExample_LoadAsyncCompleted Dim rasterImageObject As Object = 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. End Sub Private Sub rasterImageTypeConverterExample_LoadAsyncCompleted(ByVal sender As Object, ByVal e As CodecsLoadAsyncCompletedEventArgs) ' Check if the user canceled or if we have errors If e.Cancelled Then Console.WriteLine("Canceled by the user") ElseIf Not IsNothing(e.Error) Then Console.WriteLine("Error: " + e.Error.Message) Else ' Everything is OK, get the image Dim image As RasterImage = e.Image Console.WriteLine("Image at {0} loaded OK, size: {1} by {2}", e.Uri, image.Width, image.Height) image.Dispose() End If ' Unsubscribe to the event and dispose the RasterCodecs object Dim codecs As RasterCodecs = DirectCast(sender, RasterCodecs) RemoveHandler codecs.LoadAsyncCompleted, AddressOf rasterImageTypeConverterExample_LoadAsyncCompleted codecs.Dispose() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2