public ConversionCmykMask Mask { get; set; }
The CMYK conversion masking value.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ColorConversion;
public byte[] GetCmykBufferFromImage(RasterImage bgrImage)
{
// StartUp the ColorConversion.
RasterColorConverterEngine.Startup();
// Image buffer array
byte[] bgrBuffer = new byte[bgrImage.BytesPerLine * bgrImage.Height];
bgrImage.Access();
// get image buffer
for (int i = 0; i < bgrImage.Height; i++)
bgrImage.GetRow(i, bgrBuffer, i * bgrImage.BytesPerLine, bgrImage.BytesPerLine);
bgrImage.Release();
// Initialize a new Converter object
RasterColorConverterEngine converter = new RasterColorConverterEngine();
byte[] cmykBuffer = new byte[bgrImage.Height * bgrImage.Width * 4];
try
{
// Start the color conversion
converter.Start(ConversionColorFormat.Bgr, ConversionColorFormat.Cmyk, null);
// convert the image buffer
converter.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)),
0); // 0 bytes align
// stop the conversion
converter.Stop();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
RasterColorConverterEngine.Shutdown();
return cmykBuffer;
}
public RasterImage GetImageFromCmykBuffer(byte[] cmykBuffer, int width, int height)
{
// StartUp the ColorConversion.
RasterColorConverterEngine.Startup();
// Initialize a new Converter object
RasterColorConverterEngine converter = new RasterColorConverterEngine();
// Initialize an image to hold the converted buffer.
RasterImage cmykImage = null;
try
{
cmykImage = new RasterImage(RasterMemoryFlags.Conventional, width, height, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, IntPtr.Zero, 0);
// Start the color conversion
converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Bgr, null);
// convert the image buffer
converter.ConvertToImage(cmykBuffer, // converted buffer
0, // offset from the beginning of the source buffer
cmykImage, // image to be save
width, // pixels width
height, // pixels height
0, // 0 bytes align
cmykImage.BytesPerLine - (cmykImage.Width * (cmykImage.BitsPerPixel / 8)));
// stop the conversion
converter.Stop();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
// Shutdown the ColorConversion.
RasterColorConverterEngine.Shutdown();
return cmykImage;
}
public void SetParametersExample()
{
// Initialize the RasterCodecs
RasterCodecs codecs = new RasterCodecs();
// StartUp the ColorConversion.
RasterColorConverterEngine.Startup();
// The input file name
string inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp");
// load the input image as Bgr.
RasterImage bgrImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1);
int width = bgrImage.Width;
int height = bgrImage.Height;
byte[] cmykBuffer = GetCmykBufferFromImage(bgrImage);
// Initialize the Rgb buffer array
byte[] rgbBuffer = new byte[cmykBuffer.Length - cmykBuffer.Length / 4];
// Initialize a new Converter object
RasterColorConverterEngine converter = new RasterColorConverterEngine();
// Initialize a new ConversionParameters class object.
ConversionParameters convParams = new ConversionParameters();
// we want to use the built in LEAD ICC conversion method and built in conversion
convParams.Method = ConversionMethodFlags.UseBuiltIn | ConversionMethodFlags.UseIcc;
// set the active conversion method
convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn;
// Initialize WhitePoint property class.
convParams.WhitePoint = new ConversionWhitePoint();
// Set WhitePoint property.
ConversionWhitePoint whitePoint = new ConversionWhitePoint();
whitePoint.WhitePoint = ConversionWhitePointType.D50;
convParams.WhitePoint = whitePoint;
// Initialize CmykParameters property class.
convParams.CmykParameters = new ConversionCmykParameters();
// Set GcrLevel property.
ConversionCmykParameters cmykParameters = new ConversionCmykParameters();
cmykParameters.GcrLevel = 150;
convParams.CmykParameters = cmykParameters;
try
{
// Initialize the ColorConversion
converter.Start(ConversionColorFormat.Cmyk, ConversionColorFormat.Rgb, convParams);
// convert the Cmyk buffer to Rgb buffer using Built-in conversion.
converter.Convert(cmykBuffer,
0,
rgbBuffer,
0,
width,
height,
0,
bgrImage.BytesPerLine - (bgrImage.Width * (bgrImage.BitsPerPixel / 8)));
// Change the active method for conversion
convParams.Method = ConversionMethodFlags.ChangeActiveMethod | ConversionMethodFlags.ChangeCmyk;
// Switch to ICC conversion method
convParams.ActiveMethod = ConversionMethodFlags.UseIcc;
// Set Mask property.
cmykParameters.Mask = ConversionCmykMask.Gcr;
// Set GcrLevel property.
cmykParameters.GcrLevel = 175;
convParams.CmykParameters = cmykParameters;
// Update the conversion parameters
converter.SetParameters(convParams);
// convert the image buffer
converter.Convert(cmykBuffer, 0, rgbBuffer, 0, width, height, 0, 0);
// Stop the ColorConversion
converter.Stop();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
rgbBuffer = null;
}
// the output File Name.
string outputFileName = Path.Combine(LEAD_VARS.ImagesDir, "ResultImage.bmp");
// Save the converted Image
RasterImage cmykImage = GetImageFromCmykBuffer(cmykBuffer, width, height);
codecs.Save(cmykImage, outputFileName, RasterImageFormat.Bmp, 24);
// Shutdown the ColorConversion.
RasterColorConverterEngine.Shutdown();
// Shutdown the RasterColor
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}