gpt4 book ai didi

c# - 颜色转换 CMYK - RGB - Lab with WCS 使用 ICC 配置文件

转载 作者:太空宇宙 更新时间:2023-11-03 16:17:48 26 4
gpt4 key购买 nike

自上周以来,我尝试使用 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-Value 应该是 100% 左右

最佳答案

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

RGB -> XYZ -> Labthis

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com