Q: Are there any samples on how to use the Convert2CMYK and
Convert2GrayScale functions in C#? I am having a difficult time trying
to figure it out.
-----
A: Usage of 'Convert2CMYK' and 'Convert2GrayScale' methods is similar
to 'Convert2RGB'.
The following code example is extracted from ElementReaderAdvTest
sample project:
if (element.IsFilled())
{
GState gs = element.GState();
ColorSpace cs_fill = gs.GetFillColorSpace();
ColorPt fill = gs.GetFillColor();
ColorPt outc = new ColorPt();
cs_fill.Convert2RGB(fill, outc);
int r = (int)(rgb.get_c(0)*255);
int g = (int)(rgb.get_c(1)*255);
int b = (int)(rgb.get_c(2)*255);
}
To obtain grayscale value, you could use the following code:
ColorSpace cs = ....
cs_fill.Convert2Gray(in, out);
// out.get_c(0) is in the range [0..1]
int gray = (int)(out.get_c(0)*255);
similarly for CMYK:
ColorSpace cs = ....
cs_fill.Convert2CMYK(in, out);
int c = (int)(out.get_c(0)*255);
int m = (int)(out.get_c(1)*255);
int y = (int)(out.get_c(2)*255);
int k = (int)(out.get_c(3)*255);