←Select platform

ConvertFromSource Method

Summary

Converts a WPF System.Windows.Media.ImageSource object to LEADTOOLS Leadtools.RasterImage.

Syntax
C#
VB
C++
public static RasterImage ConvertFromSource( 
   ImageSource image, 
   ConvertFromSourceOptions options 
) 
  
Public Shared Function ConvertFromSource( _ 
   ByVal image As ImageSource, _ 
   ByVal options As ConvertFromSourceOptions _ 
) As RasterImage 
public: 
static RasterImage^ ConvertFromSource(  
   ImageSource^ image, 
   ConvertFromSourceOptions options 
)  

Parameters

image
The System.Windows.Media.ImageSource object containing the image data to convert.

options
Options to control the conversion operation. Currently there are no extra options and the value of this parameter must be set to ConvertFromSourceOptions.None

Return Value

A Leadtools.RasterImage object representing the converted image.

Remarks

LEADTOOLS and 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 following table shows the result bits/pixel byte order achieved when passing images with different pixel format values:

Source PixelFormat Result Bits/Pixel and byte order
System.Windows.Media.PixelFormats.Bgr101010 24 bits/pixel and RasterByteOrder.Bgr
System.Windows.Media.PixelFormats.Bgr24 24 bits/pixel and RasterByteOrder.Bgr
System.Windows.Media.PixelFormats.Bgr32 32 bits/pixel and RasterByteOrder.Bgr
System.Windows.Media.PixelFormats.Bgr555 16 bits/pixel and RasterByteOrder.Bgr
System.Windows.Media.PixelFormats.Bgr565 24 bits/pixel and RasterByteOrder.Bgr
System.Windows.Media.PixelFormats.BlackWhite 1 bits/pixel and RasterByteOrder.Rgb with a black on white palette
System.Windows.Media.PixelFormats.Cmyk32 24 bits/pixel and RasterByteOrder.Bgr
System.Windows.Media.PixelFormats.Gray16 16 bits/pixel and RasterByteOrder.Gray
System.Windows.Media.PixelFormats.Gray2 2 bits/pixel and RasterByteOrder.Rgb with a palette containing 2 shades of gray
System.Windows.Media.PixelFormats.Gray32Float 24 bits/pixel and RasterByteOrder.Bgr
System.Windows.Media.PixelFormats.Gray4 4 bits/pixel and RasterByteOrder.Rgb with a palette containing 16 shades of gray
System.Windows.Media.PixelFormats.Gray8 8 bits/pixel and RasterByteOrder.Rgb with a palette containing 256 shades of gray
System.Windows.Media.PixelFormats.Indexed1 1 bits/pixel and RasterByteOrder.Rgb with corresponding palette
System.Windows.Media.PixelFormats.Indexed2 2 bits/pixel and RasterByteOrder.Rgb with corresponding palette
System.Windows.Media.PixelFormats.Indexed4 4 bits/pixel and RasterByteOrder.Rgb with corresponding palette
System.Windows.Media.PixelFormats.Indexed8 8 bits/pixel and RasterByteOrder.Rgb with corresponding palette
System.Windows.Media.PixelFormats.Pbgra32 32 bits/pixel and RasterByteOrder.Bgr
System.Windows.Media.PixelFormats.Prgba128Float 24 bits/pixel and RasterByteOrder.Bgr
System.Windows.Media.PixelFormats.Rgb24 24 bits/pixel and RasterByteOrder.Rgb
System.Windows.Media.PixelFormats.Rgb48 48 bits/pixel and RasterByteOrder.Rgb
System.Windows.Media.PixelFormats.Rgb128Float 24 bits/pixel and RasterByteOrder.Rgb
System.Windows.Media.PixelFormats.Rgba64 64 bits/pixel and RasterByteOrder.Rgb

Example

This example will use get the WPF System.Windows.Media.ImageSource in an System.Windows.Controls.Image control, use LEADTOOLS to invert it and then set it back into the control.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Windows.Media; 
 
private void ConvertFromSourceExample(System.Windows.Controls.Image imageControl) 
{ 
   // Get the WPF/Silverlight source image in the Image control 
   ImageSource source = imageControl.Source; 
 
   // Convert it to a LEADTOOLS RasterImage 
   using (RasterImage rasterImage = RasterImageConverter.ConvertFromSource(source, ConvertFromSourceOptions.None)) 
   { 
      // Now, use LEADTOOLS to Invert the image 
      Leadtools.ImageProcessing.Color.InvertCommand cmd = new Leadtools.ImageProcessing.Color.InvertCommand(); 
      cmd.Run(rasterImage); 
 
      // Convert the back to WPF/Silverlight 
      source = RasterImageConverter.ConvertToSource(rasterImage, ConvertToSourceOptions.None); 
 
      // Set it back into the Image control 
      imageControl.Source = source; 
   } 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Windows.Media 
 
Private Sub ConvertFromSourceExample(ByVal imageControl As System.Windows.Controls.Image) 
   ' Get the WPF/Silverlight source image in the Image control 
   Dim source As ImageSource = imageControl.Source 
 
   ' Convert it to a LEADTOOLS RasterImage 
   Using rasterImage As RasterImage = RasterImageConverter.ConvertFromSource(source, ConvertFromSourceOptions.None) 
      ' Now, use LEADTOOLS to Invert the image 
      Dim cmd As New InvertCommand() 
      cmd.Run(rasterImage) 
 
      ' Convert the back to WPF/Silverlight 
      source = RasterImageConverter.ConvertToSource(rasterImage, ConvertToSourceOptions.None) 
 
      ' Set it back into the Image control 
      imageControl.Source = source 
   End Using 
End Sub 
c#[Silverlight C# Example] 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Windows.Media; 
 
private void ConvertFromSourceExample(System.Windows.Controls.Image imageControl) 
{ 
   // Get the WPF/Silverlight source image in the Image control 
   ImageSource source = imageControl.Source; 
 
   // Convert it to a LEADTOOLS RasterImage 
   using (RasterImage rasterImage = RasterImageConverter.ConvertFromSource(source, ConvertFromSourceOptions.None)) 
   { 
      // Now, use LEADTOOLS to Invert the image 
      Leadtools.ImageProcessing.Color.InvertCommand cmd = new Leadtools.ImageProcessing.Color.InvertCommand(); 
      cmd.Run(rasterImage); 
 
      // Convert the back to WPF/Silverlight 
      source = RasterImageConverter.ConvertToSource(rasterImage, ConvertToSourceOptions.None); 
 
      // Set it back into the Image control 
      imageControl.Source = source; 
   } 
} 
vb[Silverlight VB Example] 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.Windows.Media 
Imports Leadtools.ImageProcessing.Color 
 
Private Sub ConvertFromSourceExample(ByVal imageControl As System.Windows.Controls.Image) 
   ' Get the WPF/Silverlight source image in the Image control 
   Dim source As ImageSource = imageControl.Source 
 
   ' Convert it to a LEADTOOLS RasterImage 
   Using rasterImage As RasterImage = RasterImageConverter.ConvertFromSource(source, ConvertFromSourceOptions.None) 
      ' Now, use LEADTOOLS to Invert the image 
      Dim cmd As InvertCommand = New InvertCommand() 
      cmd.Run(rasterImage) 
 
      ' Convert the back to WPF/Silverlight 
      source = RasterImageConverter.ConvertToSource(rasterImage, ConvertToSourceOptions.None) 
 
      ' Set it back into the Image control 
      imageControl.Source = source 
   End Using 
End Sub 

Requirements

Target Platforms

Help Version 20.0.2019.9.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.