←Select platform

RasterImageConverter Class

Summary

Converts a LEADTOOLS Leadtools.RasterImage to and from Windows Presentation Foundation (WPF) and Silverlight image objects.

Syntax

C#
VB
C++
public static class RasterImageConverter 
  
Public MustInherit NotInheritable Class RasterImageConverter  
public ref class RasterImageConverter abstract sealed  

Remarks

The LEADTOOLS RasterImage class provides platform independent representation of an image. It serves as a working area for image manipulation and conversion. LEADTOOLS functions use this class for accessing the image in memory and for maintaining the characteristics of the image. This class contains the functionality needed to convert a LEADTOOLS Leadtools.RasterImage to and from a Windows Presentation Foundation (WPF) or Silverlight image objects.

The RasterImageConverter class contains the following functionality:

Method Description
ConvertToSource

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

ConvertFromSource

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

TestCompatible

Utility methods for testing whether a LEADTOOLS Leadtools.RasterImage is WPF/Silverlight compatible

For more information refer to RasterImage and WPF/Silverlight.

Example

C#
VB
Silverlight C#
Silverlight VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Windows.Media; 
 
public void RasterImageConverterExample() 
{ 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1.jpg"); 
   string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WPfFlipped.jpg"); 
 
   // Use LEADTOOLS to convert the source image to a format that can be loaded with WPF 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      codecs.Convert(srcFileName, destFileName1, RasterImageFormat.Jpeg, 0, 0, 0, null); 
   } 
 
   // 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 
   BitmapSource source; 
   using (RasterImage raster = RasterImageConverter.ConvertFromSource(bitmap, ConvertFromSourceOptions.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 
      source = RasterImageConverter.ConvertToSource(raster, ConvertToSourceOptions.None) as BitmapSource; 
   } 
 
   Console.WriteLine("Converted back WPF, pixel format is {0}", source.Format); 
 
   // Save the image using WPF 
   using (FileStream fs = File.Create(destFileName2)) 
   { 
      JpegBitmapEncoder encoder = new JpegBitmapEncoder(); 
      encoder.QualityLevel = 30; 
      encoder.Frames.Add(BitmapFrame.Create(source)); 
      encoder.Save(fs); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Windows.Media 
 
Public Sub RasterImageConverterExample() 
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") 
   Dim destFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.jpg") 
   Dim destFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_WPfFlipped.jpg") 
 
   ' Use LEADTOOLS to convert the source image to a format that can be loaded with WPF 
   Using codecs As New RasterCodecs() 
      codecs.Convert(srcFileName, destFileName1, RasterImageFormat.Jpeg, 0, 0, 0, Nothing) 
   End Using 
 
   ' 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 source As BitmapSource 
   Using raster As RasterImage = RasterImageConverter.ConvertFromSource(bitmap, ConvertFromSourceOptions.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 
      source = DirectCast(RasterImageConverter.ConvertToSource(raster, ConvertToSourceOptions.None), BitmapSource) 
   End Using 
 
   Console.WriteLine("Converted back WPF, pixel format is {0}", source.Format) 
 
   ' Save the image using WPF 
   Using fs As FileStream = File.Create(destFileName2) 
      Dim encoder As New JpegBitmapEncoder() 
      encoder.QualityLevel = 30 
      encoder.Frames.Add(BitmapFrame.Create(source)) 
      encoder.Save(fs) 
   End Using 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Windows.Media; 
 
public void RasterImageConverterExample() 
{ 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName1 = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.jpg"; 
 
   // Use LEADTOOLS to convert the source image to a format that can be loaded with WPF 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.Convert(srcFileName, destFileName1, RasterImageFormat.Jpeg, 0, 0, 0, null); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.Windows.Media 
Imports Leadtools.ImageProcessing.Color 
 
Public Sub RasterImageConverterExample() 
   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path & "Image1.cmp" 
   Dim destFileName1 As String = LeadtoolsExamples.Common.ImagesPath.Path & "Image1.jpg" 
 
   ' Use LEADTOOLS to convert the source image to a format that can be loaded with WPF 
   Dim codecs As RasterCodecs = New RasterCodecs() 
   codecs.Convert(srcFileName, destFileName1, RasterImageFormat.Jpeg, 0, 0, 0, Nothing) 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.