public static class RasterImageConverter 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) image objects.
The RasterImageConverter class contains the following functionality:
| Method | Description |
|---|---|
| ConvertToSource |
Converts a LEADTOOLS Leadtools.RasterImage to WPF System.Windows.Media.ImageSource |
| ConvertFromSource |
Converts a WPF System.Windows.Media.ImageSource to LEADTOOLS Leadtools.RasterImage |
| TestCompatible |
Utility methods for testing whether a LEADTOOLS Leadtools.RasterImage is WPF compatible |
For more information refer to RasterImage and WPF.
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 WPFusing (RasterCodecs codecs = new RasterCodecs()){codecs.Convert(srcFileName, destFileName1, RasterImageFormat.Jpeg, 0, 0, 0, null);}// Load the source image using WPFBitmapImage 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 objectBitmapSource 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 LEADTOOLSFlipCommand cmd = new FlipCommand(false);cmd.Run(raster);// Convert the image back to WPF using default optionssource = RasterImageConverter.ConvertToSource(raster, ConvertToSourceOptions.None) as BitmapSource;}Console.WriteLine("Converted back WPF, pixel format is {0}", source.Format);// Save the image using WPFusing (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:\LEADTOOLS23\Resources\Images";}