C# 使用 ICC 配置文件将 RGB 值转换为 CMYK?
这个问题似乎在互联网上的很多地方都有发布,但是我找不到满意的答案:(
如何使用 ICC 配置文件将 RGB 值转换为 CMYK 值?
我得到的最接近的答案就在那里,它解释了如何从 CMYK 转换为 RGB,而不是相反,这就是我需要的。 (http://stackoverflow.com/questions/4920482/cmyk-to-rgb-formula-of-photoshop/5076731#5076731)
float[] colorValues = new float[4];
colorValues[0] = c / 255f;
colorValues[1] = m / 255f;
colorValues[2] = y / 255f;
colorValues[3] = k / 255f;
System.Windows.Media.Color color = Color.FromValues(colorValues,
new Uri(@"C:\Users\me\Documents\ISOcoated_v2_300_eci.icc"));
System.Drawing.Color rgbColor = System.Drawing.Color.FromArgb(color.R, color.G, color.B);
我想我应该使用 System.Windows.Media 命名空间中的一些类/结构/方法。
System.Windows.Media.Color 结构包含一个 FromRgb 方法,但之后我无法从该 System.Windows.Media.Color 中获取 CMYK 值!
非常感谢
this question seems posted at many places over the interwebs and SO, but I could not find a satisfactory answer :(
How can I convert a RGB value to a CMYK value using an ICC profile?
The closest answer I have is there, where it explains how to convert from CMYK to RGB but not the other way around, which is what I need.
(http://stackoverflow.com/questions/4920482/cmyk-to-rgb-formula-of-photoshop/5076731#5076731)
float[] colorValues = new float[4];
colorValues[0] = c / 255f;
colorValues[1] = m / 255f;
colorValues[2] = y / 255f;
colorValues[3] = k / 255f;
System.Windows.Media.Color color = Color.FromValues(colorValues,
new Uri(@"C:\Users\me\Documents\ISOcoated_v2_300_eci.icc"));
System.Drawing.Color rgbColor = System.Drawing.Color.FromArgb(color.R, color.G, color.B);
I guess I should be using some classes/structures/methods from the System.Windows.Media namespace.
The System.Windows.Media.Color structure contains a method FromRgb, but I can't get CMYK values after, out of that System.Windows.Media.Color!
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道有任何 C# API 或库可以实现此目的。但是,如果您有足够的 C/C++ 知识来构建 C# 包装器,我会看到两个选项:
System.Windows.Media 命名空间非常有限。它背后可能有一个强大的引擎(WCS?),但只提供了一小部分。
更新:
以下是一些使用 WCS 进行转换的 C# 代码。它当然可以使用一个包装器来使其更易于使用:
I don't know of any C# API or library that can achieve this. However, if you have enough C/C++ knowledge to build a wrapper for C#, I see two options:
The System.Windows.Media namespace is very limited. There's probably a powerful engine (WCS?) behind it, but just a small part is made available.
Update:
Here's some C# code to do the conversion using WCS. It certainly could use a wrapper that would make it easier to use:
这里的答案似乎都不能令人满意地解决使用 ICC 配置文件的需要。
我发现一个 MS Connect 问题页面有一些 使用 Windows 成像组件的示例代码,使用国际商会简介。
如果您有 ICC 文件和示例 JPEG 文件,则可以设置控制台应用程序以非常快速地使用此代码。
我已将 ICC 配置文件保存在名为“Profiles”的文件夹中,并将“复制到输出目录”值设置为“始终”。
JPEG 保存到名为“Images”的文件夹中,我已将其“Build Action”值设置为“Embedded Resource”。
控制台应用程序项目需要引用以下模块:
完整的控制台应用程序(名为 CMYKConversion):
Program.cs:
Converter.cs:
None of the answers here seem to satisfactorily address the need to use an ICC profile.
I found an MS Connect issue page that has some sample code using Windows Imaging Components to convert an RBG JPEG to CMYK using an ICC profile.
If you have your ICC file and a sample JPEG file, you can set-up a console app to use this code very quickly.
I have saved the ICC profile in a folder called "Profiles" and have set the "Copy to Output Directory" value to "Always".
The JPEG is saved to a folder called "Images", and I have set its "Build Action" value to "Embedded Resource".
The console app project needs references to the following modules:
The console app in full (named CMYKConversion) :
Program.cs:
Converter.cs:
根据 MVP,GDI+ 可以读取 CMYK 但无法对其进行编码(来源:http://www.pcreview.co.uk/forums/convert-rgb-image-cmyk-t1419911.html)。他们接着说,使用 TIF 作为中介格式可能是正确的选择。
除此之外,您还可以尝试使用适用于 .NET 的 Graphics Mill 成像 SDK,网址为 http://imaging.aurigma.com/(我不隶属于该公司)。
我知道这不是一个很好的答案,但希望它能给您带来一些启发并为您指明正确的方向。
According to an MVP GDI+ can read CMYK but can't encode it (Source: http://www.pcreview.co.uk/forums/convert-rgb-image-cmyk-t1419911.html). They go on to say that using TIF as an intermediation format may be the way to go.
Other than that, you might try Graphics Mill imaging SDK for .NET at http://imaging.aurigma.com/ (I'm not affiliated with this company).
I know this isn't much of an answer, but hopefully it sheds some light and points you in the right direction.
您可以看一下:将 RGB 颜色转换为 CMYK?
虽然此转换是相当主观,因此需要 ICC 配置文件,您可能可以从 ICC 中提取该“因素”并调整公式?
将 RGB 值转换为 CMYK 需要的上下文是什么?
You could have a look at this: Convert RGB color to CMYK?
Although this conversion is fairly subjective, hence the need for the ICC profile, it may be that you can extract that "factor" from the ICC and adjust the formula?
What is the context is which you need to convert the RGB values to CMYK?