Leadtools.Windows.Media Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
ConvertFrom Method
See Also 
Leadtools.Windows.Media Namespace > RasterImageMediaConverter Class : ConvertFrom Method



srcImage
The RasterImage object containing the image data to convert.
flags
Options to control the conversion operation. The following values can be ORed together:
ValueMeaning
RasterImageMediaConverterFromFlags.NoneNo 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.
Converts a LEADTOOLS for .NET RasterImage object to Windows Presentation Foundation (WPF) ImageSource.

Syntax

Visual Basic (Declaration) 
Public Shared Function ConvertFrom( _
   ByVal srcImage As RasterImage, _
   ByVal flags As RasterImageMediaConverterFromFlags _
) As ImageSource
Visual Basic (Usage)Copy Code
Dim srcImage As RasterImage
Dim flags As RasterImageMediaConverterFromFlags
Dim value As ImageSource
 
value = RasterImageMediaConverter.ConvertFrom(srcImage, flags)
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:
ValueMeaning
RasterImageMediaConverterFromFlags.NoneNo 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.

Example

For an example, refer to RasterImageMediaConverter

Remarks

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 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

BlackWhite

1

Any other palette

Yes

Indexed1

2

Yes

Indexed2

3

No

Indexed4

4

Yes

Indexed4

5

No

Indexed8

6

No

Indexed8

7

No

Indexed8

8

Grayscale palette

Yes

Gray8

8

Color palette

Yes

Gray8

12

No

Gray16

16

Compatible grayscale data (Refer to notes on grayscale images below)

Yes

Gray16

16

Incompatible grayscale data

No

Bgra32

16

Color data

Yes

Bgr555

24

BGR color order

Yes

Bgr24

24

RGB color order

Yes

Rgb24

32

BGR color order (Refer to notes on alpha channel below)

Yes

Bgra32

32

RGB color order

No

Bgra32

48

BGR color order

No

Rgb48

48

RGB color order

Yes

Rgb48

64

BGR color order

No

Rgba64

64

RGB color order (Refer to notes on alpha channel below)

Yes

Rgba64

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:

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.

Requirements

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

See Also