/// <summary> /// Converts the RGB color format to CMYK /// </summary> /// <param name="c"></param> /// <returns>Converted color</returns> public static Cmyk RgbToCmyk(Color c) { var cmyk = new Cmyk(); double low = 1; cmyk.C = Convert.ToDouble((255d - c.R) / 255d); if (low > cmyk.C) { low = cmyk.C; } cmyk.M = Convert.ToDouble((255d - c.G) / 255d); if (low > cmyk.M) { low = cmyk.M; } cmyk.Y = Convert.ToDouble((255d - c.B) / 255d); if (low > cmyk.Y) { low = cmyk.Y; } if (low > 0) { cmyk.K = low; } return cmyk; }
/// <summary> /// Converts the CMYK color format to RGB /// </summary> /// <param name="cmyk"></param> /// <returns>Converted color</returns> public static Color CmykToRgb(Cmyk cmyk) { // To convert CMYK to RGB we first have to convert CMYK to CMY var cyan = (cmyk.C * (1 - cmyk.K)) + cmyk.K; var magenta = (cmyk.M * (1 - cmyk.K)) + cmyk.K; var yellow = (cmyk.Y * (1 - cmyk.K)) + cmyk.K; var red = Convert.ToInt32(Math.Round(cyan * 255d)); var green = Convert.ToInt32(Math.Round(magenta * 255d)); var blue = Convert.ToInt32(Math.Round(yellow * 255d)); return Color.FromArgb(red, green, blue); }