RasterImageTypeConverter is a class that can be used to convert RasterImage objects from other data types.
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.
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 |
This value is no longer supported. |
||||||||||||||||||
LeadUseNativeLoad |
This value is no longer supported. |
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 multipage TIF file hosted at an HTTP URL
http://tempuri.org/MyImage.tif?LeadFirstPage=1&LeadLastPage=1
// Load the second and third page of the multipage 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 multipage 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 multipage TIF file set as a resource
"MyImage.tif?LeadFirstPage=1&LeadLastPage=1"
// Load the second and third page of the multipage 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 multipage TIF file set as a resource as 24 bits/pixel with RGB color order
"MyImage.tif?LeadBitsPerPixel=24&LeadOrder=Rgb&LeadFirstPage=2&LeadLastPage=3"
// No longer supported.
"MyImage.tif?LeadUseWriteableBitmap=True"
// No longer supported.
"MyImage.tif?LeadUseWriteableBitmap=True&LeadUseNativeLoad=True"
Query strings are not supported for String and an array of Byte data types.
The LEADTOOLS WPF 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 shown in the example below.
This example will use the RasterImageTypeConverter to load an image from a URL.