Leadtools.Windows.Media Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.8.31
RasterImageMediaConverter Class
See Also  Members   Example 
Leadtools.Windows.Media Namespace : RasterImageMediaConverter Class




Provides interoperation between LEADTOOLS and Windows Presentation Foundation (WPF) images.

Syntax

Visual Basic (Declaration) 
Public MustInherit NotInheritable Class RasterImageMediaConverter 
Visual Basic (Usage)Copy Code
Dim instance As RasterImageMediaConverter
C# 
public static class RasterImageMediaConverter 
Managed Extensions for C++ 
public __gc abstract __sealed class RasterImageMediaConverter 
C++/CLI 
public ref class RasterImageMediaConverter abstract sealed 

Example

Visual BasicCopy Code
Public Sub RasterImageMediaConverterExample()
   Dim srcFileName As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"
   Dim destFileName1 As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.jpg"
   Dim destFileName2 As String = "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_WPfFlipped.jpg"

   ' Use LEADTOOLS to convert the source image to a format that can be loaded with WPF
   RasterCodecs.Startup()
   Dim codecs As New RasterCodecs()
   codecs.Convert(srcFileName, destFileName1, RasterImageFormat.Jpeg, 0, 0, 0, Nothing)
   codecs.Dispose()
   RasterCodecs.Shutdown()

   ' Load the source image using WPF
   Dim bitmap As New BitmapImage()
   bitmap.BeginInit()
   bitmap.UriSource = New Uri(destFileName1, UriKind.Absolute)
   bitmap.EndInit()

   Console.WriteLine("Source WPF image is loaded, pixel format is {0}", bitmap.Format)

   ' Convert the image to LEADTOOLS RasterImage object
   Dim raster As RasterImage = RasterImageMediaConverter.ConvertTo(bitmap, RasterImageMediaConverterToFlags.None)

   Console.WriteLine("Converted to RasterImage, bits/pixel is {0} and order is {1}", raster.BitsPerPixel, raster.Order)

   ' Perform image processing on the raster image using LEADTOOLS
   Dim cmd As New FlipCommand(False)
   cmd.Run(raster)

   ' Convert the image back to WPF using default options
   Dim source As BitmapSource = CType(RasterImageMediaConverter.ConvertFrom(raster, RasterImageMediaConverterFromFlags.None), BitmapSource)
   raster.Dispose()

   Console.WriteLine("Converted back WPF, pixel format is {0}", source.Format)

   ' Save the image using WPF
   Dim fs As FileStream = File.Create(destFileName2)

   Dim encoder As New JpegBitmapEncoder()
   encoder.QualityLevel = 30
   encoder.Frames.Add(BitmapFrame.Create(source))
   encoder.Save(fs)
   fs.Close()
End Sub
C#Copy Code
public void RasterImageMediaConverterExample() 

   string srcFileName = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.cmp"; 
   string destFileName1 = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1.jpg"; 
   string destFileName2 = @"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Image1_WPfFlipped.jpg"; 
 
   // Use LEADTOOLS to convert the source image to a format that can be loaded with WPF 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.Convert(srcFileName, destFileName1, RasterImageFormat.Jpeg, 0, 0, 0, null); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
 
   // Load the source image using WPF 
   BitmapImage bitmap = new BitmapImage(); 
   bitmap.BeginInit(); 
   bitmap.UriSource = new Uri(destFileName1, UriKind.Absolute); 
   bitmap.EndInit(); 
 
   Console.WriteLine("Source WPF image is loaded, pixel format is {0}", bitmap.Format); 
 
   // Convert the image to LEADTOOLS RasterImage object 
   RasterImage raster = RasterImageMediaConverter.ConvertTo(bitmap, RasterImageMediaConverterToFlags.None); 
 
   Console.WriteLine("Converted to RasterImage, bits/pixel is {0} and order is {1}", raster.BitsPerPixel, raster.Order); 
 
   // Perform image processing on the raster image using LEADTOOLS 
   FlipCommand cmd = new FlipCommand(false); 
   cmd.Run(raster); 
 
   // Convert the image back to WPF using default options 
   BitmapSource source = RasterImageMediaConverter.ConvertFrom(raster, RasterImageMediaConverterFromFlags.None) as BitmapSource; 
   raster.Dispose(); 
 
   Console.WriteLine("Converted back WPF, pixel format is {0}", source.Format); 
 
   // Save the image using WPF 
   FileStream fs = File.Create(destFileName2); 
 
   JpegBitmapEncoder encoder = new JpegBitmapEncoder(); 
   encoder.QualityLevel = 30; 
   encoder.Frames.Add(BitmapFrame.Create(source)); 
   encoder.Save(fs); 
   fs.Close(); 
}

Remarks

The RasterImageMediaConverter class provides methods to convert a RasterImage object to and from an ImageSource.

The ConvertFrom method will convert a RasterImage object to a WPF ImageSource. The flags in the RasterImageMediaConverterFromFlags enumeration can be used to control the conversion operation.

The ConvertTo method will convert a WPF ImageSource object to a RasterImage. The flags in the RasterImageMediaConverterToFlags enumeration can be used to control the conversion operation.

The conversion works by copying the image data over to the new destination. Currently, there is no support for sharing memory between a RasterImage and an ImageSource.

Inheritance Hierarchy

System.Object
   Leadtools.Windows.Media.RasterImageMediaConverter

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