public void SetParameters(
ConversionParameters parameters
)
parameters
A ConversionParameters object that describes the conversion properties to be set.
The parameters parameter should not be null(Nothing). If it is, this method will fail.
This example will convert a CMYK buffer to RGB buffer.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ColorConversion;
using Leadtools.ImageProcessing;
public string builtInOutputFile = Path.Combine(LEAD_VARS.ImagesDir, "ColorConversion", "BuiltInCmykToRgb.bmp");
public string parametersOutputFile = Path.Combine(LEAD_VARS.ImagesDir, "ColorConversion", "ParametersCmykToRgb.bmp");
public void SetParametersExample()
{
// StartUp the Color Conversion Engine
RasterColorConverterEngine.Startup();
// Initialize a new Converter object
RasterColorConverterEngine colorConverterEngine = new RasterColorConverterEngine();
// Input file name
string inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp");
// Load the input image as BGR
using (RasterCodecs codecs = new RasterCodecs())
using (RasterImage bgrImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1))
{
// Image width and height
int width = bgrImage.Width;
int height = bgrImage.Height;
// Get BGR buffer
byte[] bgrBuffer = new byte[bgrImage.BytesPerLine * bgrImage.Height];
bgrImage.Access();
bgrImage.GetRow(0, bgrBuffer, 0, bgrImage.BytesPerLine * bgrImage.Height);
bgrImage.Release();
// Convert to CMYK
byte[] cmykBuffer = new byte[bgrImage.Height * bgrImage.Width * 4];
colorConverterEngine.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Cmyk, null);
colorConverterEngine.Convert(bgrBuffer, // Input buffer
0, // Offset from the beginning of the source buffer
cmykBuffer, // Output buffer
0, // Offset from the beginning of the destination buffer
bgrImage.Width, // Pixels width
bgrImage.Height, // Pixels height
bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8)), // Scanline alignment for input buffer
0); // Scanline alignment for output buffer
colorConverterEngine.Stop();
// Set White Point and CMYK parameters for conversion with built-in method
ConversionParameters convParams = new ConversionParameters();
convParams.Method = ConversionMethodFlags.UseBuiltIn | ConversionMethodFlags.UseIcc;
convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn;
convParams.WhitePoint = new ConversionWhitePoint() { WhitePoint = ConversionWhitePointType.D50 };
convParams.CmykParameters = new ConversionCmykParameters() { GcrLevel = 150 };
// Convert to RGB
byte[] rgbBuffer = new byte[cmykBuffer.Length - cmykBuffer.Length / 4];
colorConverterEngine.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Rgb, convParams);
colorConverterEngine.Convert(cmykBuffer,
0,
rgbBuffer,
0,
width,
height,
0,
bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8)));
// Save output RGB image
using(RasterImage outputRgbImage = new RasterImage(RasterMemoryFlags.Conventional, width, height, 24, RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, null, rgbBuffer, rgbBuffer.Length))
codecs.Save(outputRgbImage, builtInOutputFile, RasterImageFormat.Bmp, 24);
// Change conversion parameters
convParams.Method = ConversionMethodFlags.ChangeActiveMethod | ConversionMethodFlags.ChangeCmyk;
convParams.ActiveMethod = ConversionMethodFlags.UseIcc;
convParams.CmykParameters = new ConversionCmykParameters() { GcrLevel = 150, Mask = ConversionCmykMask.Gcr };
// Update and convert using the new conversion parameters
colorConverterEngine.SetParameters(convParams);
colorConverterEngine.Convert(cmykBuffer, 0, rgbBuffer, 0, width, height, 0, 0);
colorConverterEngine.Stop();
// Save output RGB image
using (RasterImage outputRgbImage = new RasterImage(RasterMemoryFlags.Conventional, width, height, 24, RasterByteOrder.Rgb, RasterViewPerspective.TopLeft, null, rgbBuffer, rgbBuffer.Length))
codecs.Save(outputRgbImage, parametersOutputFile, RasterImageFormat.Bmp, 24);
}
// Dispose of color converter engine
colorConverterEngine.Dispose();
// Shutdown the RasterColor Color Converter Engine
RasterColorConverterEngine.Shutdown();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}