Converts image data in a managed buffer from one color conversion model directly to RGB\BGR using built-in algorithms, and sets the output as a RasterImage.
public static void ConvertDirectToImage(ConversionColorFormat srcFormat,ConversionColorFormat destFormat,byte[] srcBuffer,int srcBufferOffset,RasterImage image,int width,int height,int inAlign,int outAlign)
srcFormat
Format of the input data.
destFormat
Format of the output data.
srcBuffer
A pointer to the buffer containing the input data.
srcBufferOffset
Offset to the first byte of the srcBuffer data buffer.
image
A RasterImage object that will hold the converted data.
width
Width of pixels to be processed.
height
Height of pixels to be processed.
inAlign
Each scanline in the input buffer is a multiple of inAlign bytes.
outAlign
Each scanline in the output buffer is a multiple of outAlign bytes.
There is no need to call the Start and Stop methods to initialize or stop the conversion engine.
Converting from any color space to YCCK color space is currently not supported.
For more information about Alignment Parameters, refer to Alignment Parameters.
To convert to the Y41P type, the input buffer length must be a multiple of 8.
This example will convert BGR image to Lab color space, and then convert the Lab buffer to RasterImage, using the static method ConvertDirectToImage.
using Leadtools;using Leadtools.Codecs;using Leadtools.ColorConversion;using Leadtools.ImageProcessing;public string outputFile = Path.Combine(LEAD_VARS.ImagesDir, "ColorConversion", "LabToBgr.bmp");public void ConvertDirectToImageExample(){// Start up the ColorConversion.RasterColorConverterEngine.Startup();// Input file namestring inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");// Load the input image as BGRusing (RasterCodecs codecs = new RasterCodecs())using (RasterImage bgrImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1)){// Get the input image buffer arraybyte[] bgrBuffer = new byte[bgrImage.BytesPerLine * bgrImage.Height];bgrImage.Access();bgrImage.GetRow(0, bgrBuffer, 0, bgrImage.BytesPerLine * bgrImage.Height);bgrImage.Release();// Create the destination CIELab bufferbyte[] labBuffer = new byte[bgrBuffer.Length];// Initialize a new Converter objectusing (RasterColorConverterEngine colorConverterEngine = new RasterColorConverterEngine()){// Conversion parametersConversionParameters convParams = new ConversionParameters();convParams.Method = ConversionMethodFlags.ChangeLab;// CIELab conversion parametersConversionLabParameters labParameters = ConversionLabParameters.Empty;labParameters.AOffset = 128;labParameters.ARange = 170;labParameters.BOffset = 96;labParameters.BRange = 200;labParameters.LOffset = 0;labParameters.LRange = 100;labParameters.Mask = ConversionLabMaskFlags.AOffset |ConversionLabMaskFlags.ARange |ConversionLabMaskFlags.BOffset |ConversionLabMaskFlags.BRange |ConversionLabMaskFlags.LOffset |ConversionLabMaskFlags.LRange;convParams.LabParameters = labParameters;// Convert BGR to CIELab buffer using the previous parameterscolorConverterEngine.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Lab, null);colorConverterEngine.SetParameters(convParams);colorConverterEngine.Convert(bgrBuffer, // input buffer0, // offset from the beginning of the source bufferlabBuffer, // output buffer0, // offset from the beginning of the destination bufferbgrImage.Width, // pixels widthbgrImage.Height, // pixels heightbgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8)), // Scanline alignment for input buffer0); // Scanline alignment for output buffercolorConverterEngine.Stop();// To view the image after converison, convert the now CIELab buffer to a BGR imageRasterImage dstImage = new RasterImage(RasterMemoryFlags.Conventional, bgrImage.Width, bgrImage.Height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0);RasterColorConverterEngine.ConvertDirectToImage(ConversionColorFormat.Lab,ConversionColorFormat.Bgr,labBuffer, // Source buffer0, // Offset from the beginning of the source bufferdstImage, // Destination ImagebgrImage.Width, // Pixels widthbgrImage.Height, // Pixels height0, // Scanline alignment for input bufferbgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8))); // Scanline alignment for output buffer// Save the converted RGB Imagecodecs.Save(dstImage, outputFile, RasterImageFormat.Bmp, 24);}}// Shutdown the ColorConversion.RasterColorConverterEngine.Shutdown();}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";}