public void ConvertToImage(
IntPtr srcBuffer,
long srcBufferOffset,
RasterImage image,
int width,
int height,
int inAlign,
int outAlign
)
srcBuffer
A pointer to a buffer containing the input data.
srcBufferOffset
Offset to the first byte of the srcBuffer data buffer.
image
An 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 scan line in the output buffer is a multiple of outAlign bytes.
The active conversion method is specified in the ConversionParameters object when calling the Start method. To change the active method, use the SetParameters method. Only methods supported by the initialized converter should be specified. The conversion is done if the BGR or RGB Color Space was specified as the destination format when the Start method was called. For more information about Alignment Parameters, refer to Alignment Parameters. To convert to the Y41P type the input image width must be multiple of 8
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ColorConversion;
using Leadtools.ImageProcessing;
public string outputFile = Path.Combine(LEAD_VARS.ImagesDir, "ColorConversion", "WhitePoint.tif");
public void WhitePointPropertyExample()
{
// StartUp the ColorConversion.
RasterColorConverterEngine.Startup();
// Input file name
string inputFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
// Load the input image as Rgb
using (RasterCodecs codecs = new RasterCodecs())
using (RasterImage rgbImage = codecs.Load(inputFileName, 24, CodecsLoadByteOrder.Rgb, 1, 1))
{
// Get image buffer
byte[] rgbBuffer = new byte[rgbImage.BytesPerLine * rgbImage.Height];
rgbImage.Access();
for (int i = 0; i < rgbImage.Height; i++)
rgbImage.GetRow(i, rgbBuffer, i * rgbImage.BytesPerLine, rgbImage.BytesPerLine);
rgbImage.Release();
// Initialize the Cmyk buffer array
byte[] cmykBuffer = new byte[rgbImage.Height * rgbImage.Width * 4];
using (RasterColorConverterEngine colorConverterEngine = new RasterColorConverterEngine())
{
// Conversion parameters
ConversionParameters convParams = new ConversionParameters();
convParams.Method = ConversionMethodFlags.UseBuiltIn;
convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn;
convParams.Quantization = 8;
// WhitePoint
ConversionWhitePoint whitePoint = ConversionWhitePoint.Empty;
whitePoint.WhitePoint = ConversionWhitePointType.D50;
whitePoint.XWhite = 0;
whitePoint.YWhite = 0;
convParams.WhitePoint = whitePoint;
// CMYK
ConversionCmykParameters cmykParameters = new ConversionCmykParameters();
cmykParameters.GcrLevel = 150;
convParams.CmykParameters = cmykParameters;
// Convert RGB to CMYK with above parameters
colorConverterEngine.Start(ConversionColorFormat.Rgb, ConversionColorFormat.Cmyk, convParams);
colorConverterEngine.Convert(rgbBuffer, // Source buffer
0, // Offset to the beginning of source buffer
cmykBuffer, // Destination buffer
0, // Offset to the beginning of destination buffer
rgbImage.Width, // Pixels width
rgbImage.Height, // Pixels height
rgbImage.BytesPerLine - (rgbImage.Width * (rgbImage.BitsPerPixel / 8)), // Scanline alignment for source buffer
0); // Scanline alignment for destination buffer
colorConverterEngine.Stop();
// Save CMYK Image
// Split CMYK buffer to separate C, M, Y, and K planes
byte[] cBuffer = new byte[cmykBuffer.Length / 4];
byte[] mBuffer = new byte[cmykBuffer.Length / 4];
byte[] yBuffer = new byte[cmykBuffer.Length / 4];
byte[] kBuffer = new byte[cmykBuffer.Length / 4];
int index, cIndex, mIndex, yIndex, kIndex;
index = cIndex = mIndex = yIndex = kIndex = 0;
foreach (byte cmykByte in cmykBuffer)
{
switch (++index % 4)
{
case 0:
kBuffer[kIndex++] = cmykByte;
break;
case 1:
cBuffer[cIndex++] = cmykByte;
break;
case 2:
mBuffer[mIndex++] = cmykByte;
break;
case 3:
yBuffer[yIndex++] = cmykByte;
break;
}
}
// Combine planes into a single RasterImage with a page for each plane
using (RasterImage cPlane = new RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 0, RasterByteOrder.Gray, RasterViewPerspective.TopLeft, null, cBuffer, cBuffer.Length))
using (RasterImage mPlane = new RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 0, RasterByteOrder.Gray, RasterViewPerspective.TopLeft, null, mBuffer, mBuffer.Length))
using (RasterImage yPlane = new RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 0, RasterByteOrder.Gray, RasterViewPerspective.TopLeft, null, yBuffer, yBuffer.Length))
using (RasterImage kPlane = new RasterImage(RasterMemoryFlags.Conventional, rgbImage.Width, rgbImage.Height, 0, RasterByteOrder.Gray, RasterViewPerspective.TopLeft, null, kBuffer, yBuffer.Length))
{
cPlane.AddPage(mPlane);
cPlane.AddPage(yPlane);
cPlane.AddPage(kPlane);
// Save the 4 page CMYK plances Raster Image as a CMYK Image
codecs.SaveCmykPlanes(cPlane, outputFile, RasterImageFormat.TifCmyk, 0, 0, CodecsSavePageMode.Overwrite);
}
}
}
// Shutdown the ColorConversion.
RasterColorConverterEngine.Shutdown();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}