DotImage has the ability to convert an image from RGB to CMYK, CMYK to RGB, or RGB to RGB using the ConvertColorSpace method in the ColorTransform object located in the Atalasoft.Imaging.ColorManagement namespace. There also exists a method ConvertColors which will convert an array of colors from within the RGB colorspace. However since this method uses the .NET color object, it's not designed to convert colors to different colorspaces. Since an image contains pixels which are just color values, the workaround is to make an image that contains the colors you wish to transform, then convert the colorspace. Here is example code for doing this that uses unsafe code.
[C#]
byte[] pal = new byte[256 * 4];
for (int i = 0; i < pal.Length; i++)
{
pal[i] = (byte)(i / 4);
}
AtalaImage rgbPal;
unsafe
{
fixed(byte* pPal = (byte*)&pal[0])
{
AtalaImage palImage = new AtalaImage((IntPtr)pPal, 256, 1, PixelFormat.Pixel32bppCmyk);
palImage.ColorProfile = new ColorProfile(@"C:\WINDOWS\system32\spool\drivers\color\EuroscaleCoated.icc");
rgbPal = palImage.GetChangedPixelFormat(PixelFormat.Pixel24bppBgr);
}
}
for (int i = 0; i < 256; i++)
{
Console.WriteLine(rgbPal.GetPixelColor(i, 0).ToString());
}
Console.ReadLine();
Original Article:
Q10100 - INFO: Converting the colorspace of individual colors or a palette