来自Software Engineering Stack Exchange的

This question was migrated,因为可以在Stack Overflow上进行回答。
                            Migrated 6年前。
                        
                    
                
                            
                    
从上周开始,我尝试使用Windows颜色系统进行颜色转换。通过从CMYK到RGB的转换,我得到了正确的值:

    // Example CMYK - VALUES with 0
    float[] cmykValues = new float[4];
    cmykValues[0] = 0f / 255f;
    cmykValues[1] = 0f / 255f;
    cmykValues[2] = 0f / 255f;
    cmykValues[3] = 0f / 255f;

    System.Windows.Media.Color color = Color.FromValues(cmykValues, new Uri(@"ISOcoated_v2_300_eci.icc"));
    System.Drawing.Color rgbColor = System.Drawing.Color.FromArgb(color.R, color.G, color.B);


当我尝试将RGB值转换为Lab值时,我得到了不正确的Lab-结果:

[StructLayout(LayoutKind.Sequential)]
public struct RGBColor
{
    public ushort red;
    public ushort green;
    public ushort blue;
    public ushort pad;
};

[StructLayout(LayoutKind.Sequential)]
public struct LABColor
{
    public ushort L;
    public ushort a;
    public ushort b;
    public ushort pad;
};

 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(@"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();
 LABColor[] labColors = new LABColor[1];
 labColors[0] = new LABColor();

 rgbColors[0].red    = Convert.ToUInt16(rgbColor.R * 257);
 rgbColors[0].green  = Convert.ToUInt16(rgbColor.G * 257);
 rgbColors[0].blue   = Convert.ToUInt16(rgbColor.B * 257);

 success = TranslateColors(transform, rgbColors, 1, ColorType.RGB, labColors, ColorType.Lab);

 double colorL = Convert.ToDouble(labColors[0].L) / 65535;
 double colorA = Convert.ToDouble(labColors[0].a) / 65535;
 double colorB = Convert.ToDouble(labColors[0].b) / 65535;


当我将CMYK值(0; 0; 0; 0)转换为RGB(= 254:254; 254)并将RGB值转换为Lab时,我得到以下值:

L = 0.0039978637360036373
a = 0.002777141984552145
b = 0.0030670634005218744


但L值应约为100%

最佳答案

嗯从彩色监视器(CMYK)转换为与设备无关的颜色模型(RGB)时,我认为您不需要使用打印配置文件(Lab)。

RGB -> XYZ -> Labthis

关于c# - 颜色转换CMYK-RGB-使用ICC配置文件的WCS实验室,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15203580/

10-16 15:13