public static void Test() { bool success; StringBuilder profileName = new StringBuilder(256); uint size = (uint)profileName.Capacity * 2; success = GetStandardColorSpaceProfile(0, LogicalColorSpace.sRGB, profileName, ref size); ProfileFilename sRGBFilename = new ProfileFilename(profileName.ToString()); IntPtr hSRGBProfile = OpenColorProfile(sRGBFilename, ProfileRead, FileShare.Read, CreateDisposition.OpenExisting); ProfileFilename isoCoatedFilename = new ProfileFilename(@"C:\Users\me\Documents\ISOcoated_v2_300_eci.icc"); IntPtr hIsoCoatedProfile = OpenColorProfile(isoCoatedFilename, ProfileRead, FileShare.Read, CreateDisposition.OpenExisting); IntPtr[] profiles = new IntPtr[] { hSRGBProfile, hIsoCoatedProfile }; uint[] intents = new uint[] { IntentPerceptual }; IntPtr transform = CreateMultiProfileTransform(profiles, 2, intents, 1, ColorTransformMode.BestMode, IndexDontCare); RGBColor[] rgbColors = new RGBColor[1]; rgbColors[0] = new RGBColor(); CMYKColor[] cmykColors = new CMYKColor[1]; cmykColors[0] = new CMYKColor(); rgbColors[0].red = 30204; rgbColors[0].green = 4420; rgbColors[0].blue = 60300; success = TranslateColors(transform, rgbColors, 1, ColorType.RGB, cmykColors, ColorType.CMYK); success = DeleteColorTransform(transform); success = CloseColorProfile(hSRGBProfile); success = CloseColorProfile(hIsoCoatedProfile); }
internal static ICmyk TranslateColor(IRgb rgb, Uri cmykProfile) { var profileName = new StringBuilder(256); var size = (uint)profileName.Capacity * 2; GetStandardColorSpaceProfile(0, LogicalColorSpace.SRgb, profileName, ref size); var rgbFilename = new ProfileFilename(profileName.ToString()); return(TranslateColor(rgb, cmykProfile, new Uri(rgbFilename.profileData))); }
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 static extern IntPtr OpenColorProfile( [MarshalAs(UnmanagedType.LPStruct)] ProfileFilename profile, uint desiredAccess, FileShare shareMode, CreateDisposition creationMode);