internal static ICmyk TranslateColor(IRgb rgb, Uri cmykProfile, Uri rgbProfile) { const double dividend = 65535; var profileName = new StringBuilder(256); var size = (uint)profileName.Capacity * 2; ProfileFilename sRgbFilename; if (rgbProfile == null) { GetStandardColorSpaceProfile(0, LogicalColorSpace.sRgb, profileName, ref size); sRgbFilename = new ProfileFilename(profileName.ToString()); } else { sRgbFilename = new ProfileFilename(rgbProfile.LocalPath); } var hSRgbProfile = OpenColorProfile(sRgbFilename, ProfileRead, FileShare.Read, CreateDisposition.OpenExisting); var isoCoatedFilename = new ProfileFilename(cmykProfile.LocalPath); var hIsoCoatedProfile = OpenColorProfile(isoCoatedFilename, ProfileRead, FileShare.Read, CreateDisposition.OpenExisting); var profiles = new[] { hSRgbProfile, hIsoCoatedProfile }; var intents = new[] { IntentPerceptual }; var transform = CreateMultiProfileTransform(profiles, 2, intents, 1, ColorTransformMode.BestMode, IndexDontCare); var rgbColors = new RgbColor[1]; rgbColors[0] = new RgbColor(); var cmykColors = new CmykColor[1]; cmykColors[0] = new CmykColor(); rgbColors[0].red = (ushort)(rgb.R * dividend / 255.0); rgbColors[0].green = (ushort)(rgb.G * dividend / 255.0); rgbColors[0].blue = (ushort)(rgb.B * dividend / 255.0); TranslateColors(transform, rgbColors, 1, ColorType.Rgb, cmykColors, ColorType.CMYK); DeleteColorTransform(transform); CloseColorProfile(hSRgbProfile); CloseColorProfile(hIsoCoatedProfile); return(new Cmyk { C = cmykColors[0].cyan / dividend, M = cmykColors[0].magenta / dividend, Y = cmykColors[0].yellow / dividend, K = cmykColors[0].black / dividend }); }
private void SetRgbToCmyk() { pb1.BackColor = Color.FromArgb(trbRed.Value, trbGreen.Value, trbBlue.Value); Converter cnv = new Converter(); CmykColor cm = cnv.rgbToCmyk(trbRed.Value, trbGreen.Value, trbBlue.Value); trbCyan.Value = cm.c; trbMagenta.Value = cm.m; trbYellow.Value = cm.y; trbKey.Value = cm.k; }
private void SetHlsToCmyk() { Converter preCnv = new Converter(); RgbColor rc = Converter.HlsToRgb(trbHue.Value, trbLight.Value, trbSaturation.Value); pb1.BackColor = Color.FromArgb(rc.r, rc.g, rc.b); Converter cnv = new Converter(); CmykColor cm = cnv.rgbToCmyk(rc.r, rc.g, rc.b); trbCyan.Value = cm.c; trbMagenta.Value = cm.m; trbYellow.Value = cm.y; trbKey.Value = cm.k; }
private void Button1_Click(object sender, EventArgs e) { if (colorDialog1.ShowDialog() == DialogResult.Cancel) { return; } Converter preCnv = new Converter(); CmykColor cm = preCnv.rgbToCmyk(colorDialog1.Color.R, colorDialog1.Color.G, colorDialog1.Color.B); pb1.BackColor = colorDialog1.Color; trbCyan.Value = cm.c; trbMagenta.Value = cm.m; trbYellow.Value = cm.y; trbKey.Value = cm.k; SetCmykToHls(); }