Provides interoperation between LEADTOOLS and Windows Presentation Foundation (WPF) images.
Syntax
Visual Basic (Declaration) | |
---|
Public MustInherit NotInheritable Class 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 Basic | Copy 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"
RasterCodecs.Startup()
Dim codecs As New RasterCodecs()
codecs.Convert(srcFileName, destFileName1, RasterImageFormat.Jpeg, 0, 0, 0, Nothing)
codecs.Dispose()
RasterCodecs.Shutdown()
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)
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)
Dim cmd As New FlipCommand(False)
cmd.Run(raster)
Dim source As BitmapSource = CType(RasterImageMediaConverter.ConvertFrom(raster, RasterImageMediaConverterFromFlags.None), BitmapSource)
raster.Dispose()
Console.WriteLine("Converted back WPF, pixel format is {0}", source.Format)
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
Inheritance Hierarchy
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