RasterImageTypeConverter is a class that can be used to convert RasterImage objects from other data types.
This class derives from the standard .NET TypeConverter class to provides functionality for converting RasterImage objects from other data types.
The following data types are supported:
The CanConvertFrom 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 method will try to convert the object passed into the value parameter to a valid RasterImage object.
For Uri and String source objects, LEADTOOLS supports optional extra parameters passed as standard HTML query string to fine tune the loading of 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-bit, 24-bit, 32-bit, 48-bit, 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 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 RasterImage will be loaded with the native filter codecs instead of LEADTOOLS. Refer to CodecsLoadOptions.UseNativeLoad for more information. |
value | Meaning |
---|---|
0 | Keep the original file's pixel depth (Do not convert). |
1 to 8 | The specified bits per pixel in the resulting image. |
12 | 12 bits per pixel in the resulting image. |
16 | 16 bits per pixel in the resulting image. |
24 | 24 bits per pixel in the resulting image. |
32 | 32 bits per pixel in the resulting image. |
48 | 48 bits per pixel in the resulting image. |
64 | 64 bits per pixel in the resulting image. |
Value | Meaning |
---|---|
Rgb | Red, green, and blue color order in memory |
Bgr | Blue, green, and red color order in memory |
Gray | 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are only supported in the Document/Medical Imaging editions. |
RgbOrGray | Load the image as red, green, blue OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in the Document/Medical Imaging editions |
BgrOrGray | Load the image as blue, green, red OR as a 12 or 16-bit grayscale image. 12 and 16-bit grayscale images are supported in the Document/Medical Imaging editions |
Romm | ROMM order. ROMM only supports 24 and 48-bit images |
BgrOrGrayOrRomm | Load the image as blue, green, red OR as a 12 or 16-bit grayscale image OR as ROMM. 12 and 16-bit grayscale images are supported in the Document/Medical Imaging editions only. ROMM only supports 24 and 48-bit color images. |
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=3
The RasterImageTypeConverter is also used when loading a resource image from XAML as a 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 String and an array of Byte data types.
The LEADTOOLS WPF and Silverlight controls use the RasterImageTypeConverter to load a RasterImage from a XAML file.
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 show in the example below.