Visual Basic (Declaration) | |
---|---|
Public Shared Function ConvertFrom( _ ByVal srcImage As RasterImage, _ ByVal flags As RasterImageMediaConverterFromFlags _ ) As ImageSource |
Visual Basic (Usage) | Copy Code |
---|---|
|
C# | |
---|---|
public static ImageSource ConvertFrom( RasterImage srcImage, RasterImageMediaConverterFromFlags flags ) |
C++/CLI | |
---|---|
public: static ImageSource ConvertFrom( RasterImage srcImage, RasterImageMediaConverterFromFlags flags ) |
Parameters
- srcImage
- The RasterImage object containing the image data to convert.
- flags
-
Options to control the conversion operation. The following values can be ORed together:
Value Meaning RasterImageMediaConverterFromFlags.None No options RasterImageMediaConverterFromFlags.KeepAlphaValues Use srcImage alpha values when converting from and to a pixel format that supports an alpha channel. If this flag is not set, the alpha values in srcImage will be ignored (if present) and an alpha value of all 1's (opaque) will be used instead. If the destination pixel format does not support alpha, this value is ignored. RasterImageMediaConverterFromFlags.KeepViewPerspective Do not rotate or flip the destination image if srcImage has a view perspective other than RasterViewPerspective.TopLeft/>. For example, if srcImage has a view perspective of RasterViewPerspective.BottomLeft, the result destination image will be flipped. If this flag is not present, the conversion method will rotate/flip the scanlines as needed. RasterImageMediaConverterFromFlags.IgnoreLowHighBitsOnGrayImages Ignore the LowBit and HighBit values if srcImage is a grayscale image with bits per pixel value of 12 or 16. If this flag is not present, the low/high bit values will be used when converting the scanlines of the destination image.
Return Value
An ImageSource object representing the converted image.LEADTOOLS for .NET and Windows Presentation Foundation (WPF) support different pixel formats. These pixel formats may not be identical in some cases. The conversion process takes care of converting scanlines to a suitable format that best matches the source data.
The ConvertFrom method supports converting from any RasterImage regardless of the combination of the bits/pixel, compression, color order, grayscale properties of the source image. The ConvertFrom method will always returns a valid WPF ImageSource by allocating temporary memory for the data and performing the necessary conversion on it.
In some cases, the RasterImage data is compatible with WPF and no conversion takes place. Converting a compatible RasterImage to WPF ImageSource is faster and takes less resources than converting a non-compatible image. Please note that currently WPF does not allow direct access to the raw data pointers where the image data is stored. Therefore, there is always at least one copy operation regardless if the source data can be used directly by a WPF image (For example, through the use of the BitmapSource.Create method).
For a RasterImage to be compatible with WPF, it must have the following properties:
The RasterImage must have conventional memory, not disk and nor tiled memory. ( RasterImage.IsConventionalMemory must be true and RasterImage.IsDiskMemory, RasterImage.IsTiled, RasterImage.IsGlobalMemory and RasterImage.IsMirrored must all be false)
The RasterImage data must not be compressed (RasterImage.IsCompressed and RasterImage.IsSuperCompressed must both be false)
The RasterImage data must not be signed (RasterImage.Signed must be false)
The RasterImage must have compatible bits/pixel and color order values according the table below.
The following table lists the source RasterImage bits/pixel and source data properties and whether each combination is compatible with WPF.
Source Bits/Pixel | More Source Data | Compatible | Result PixelFormat |
---|---|---|---|
1 |
Black on white palette |
Yes |
|
1 |
Any other palette |
Yes |
|
2 |
Yes |
||
3 |
No |
||
4 |
Yes |
||
5 |
No |
||
6 |
No |
||
7 |
No |
||
8 |
Grayscale palette |
Yes |
|
8 |
Color palette |
Yes |
|
12 |
No |
||
16 |
Compatible grayscale data (Refer to notes on grayscale images below) |
Yes |
|
16 |
Incompatible grayscale data |
No |
|
16 |
Color data |
Yes |
|
24 |
BGR color order |
Yes |
|
24 |
RGB color order |
Yes |
|
32 |
BGR color order (Refer to notes on alpha channel below) |
Yes |
|
32 |
RGB color order |
No |
|
48 |
BGR color order |
No |
|
48 |
RGB color order |
Yes |
|
64 |
BGR color order |
No |
|
64 |
RGB color order (Refer to notes on alpha channel below) |
Yes |
Notes on gray scale images
Both LEADTOOLS and Windows Presentation Foundation support 16 bit grayscale image data. However LEADTOOLS supports extra features such as low/high bit values and color lookup tables. For a LEADTOOLS 16-bit grayscale RasterImage to be compatible with a WPF image with Gray16, the following conditions must be met:
The value of RasterImage.UseLookupTable must be false
The low/high bit values must not be used. Either, the values of RasterImage.LowBit and RasterImage.HighBit are set to the default values or the RasterImageMediaConverterFromFlags.IgnoreLowHighBitsOnGrayImages flag must be passed to the ConvertFrom method
Notes on alpha channel
When converting images that support an alpha channel (32 or 64 bits/pixel images), the ConvertFrom method supports masking out the alpha channel bits to all 1’s through or using the source image alpha channel bits through the use of the RasterImageMediaConverterFromFlags.KeepAlphaValues flag. Masking out the alpha channel bits requires the source data image to be processed and hences, the image will not be compatible with WPF.
Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family