[FlagsAttribute()]
public enum ConvertFromSourceOptions
Value | Member | Description |
---|---|---|
0x00000000 | None | Default |
0x00000001 | UseWritableBitmap |
Use WriteableBitmap for image data storage.
Note: |
0x00000002 | AutoDetectAlpha |
Indicates LEADTOOLS should automatically detect if the image data contains meaningful alpha channel values, and if so, set the RasterImage.PremultiplyAlpha property accordingly.
Note: |
0x00000004 | FastConvertTo1Bit |
Fast conversion to 1-bit black on white. Use this flag to convert any System.Windows.Media.ImageSource to a 1-bit per pixel Leadtools.RasterImage object with black on white palette. Useful for quickly converting System.Windows.Media.ImageSource to Leadtools.RasterImage; suitable for barcode or OCR recognition.
Note: |
This enumeration is used as the options for converting Windows Presentation Foundation (WPF) System.Windows.Media.ImageSource objects to LEADTOOLS Leadtools.RasterImage through the RasterImageConverter.ConvertFromSource method.
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 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:\LEADTOOLS22\Resources\Images";
}