在WPF / XAML中使用CMYK颜色

时间:2021-02-22 14:14:22

Is there any way to specify CMYK colours directly in a XAML document?

有没有办法直接在XAML文档中指定CMYK颜色?

prefixing them with # character will create RGB colours, but how to specify a CMYK colour?

用#字符添加前缀将创建RGB颜色,但如何指定CMYK颜色?

Some notes:

一些说明:

  1. The question is NOT about converting from CMYK to RGB but to use real CMYK
  2. 问题不是关于从CMYK转换为RGB而是使用真正的CMYK
  3. The purpose is to allow generated XPS documents (using System.Windows.Xps.Packaging for example) see the colour as CMYK and generate colour codes as "ContextColor /swopcmykprofile.icc a,b,c,d,e" not as "#aarrggbb"
  4. 目的是允许生成的XPS文档(例如使用System.Windows.Xps.Packaging)将颜色视为CMYK并生成颜色代码为“ContextColor /swopcmykprofile.icc a,b,c,d,e”而不是“# AARRGGBB”

I have tried to define CMYK colours by using ColorContext without any success.

我试图通过使用ColorContext来定义CMYK颜色,但没有任何成功。

2 个解决方案

#1


7  

OK again! It turned out to be much more easier than what I though: CMYK is directly usable in XAML:

好了!事实证明它比我更容易:CMYK可直接在XAML中使用:

<Grid Background="ContextColor file://C:/WINDOWS/system32/spool/drivers/color/EuroscaleCoated.icc 1.0,0.0,0.0,1.0,1.0">

#2


6  

OK! I found the answer:

好!我找到了答案:

The way that WPF uses colour models is by System.Windows.Media.Color's static constructor FromValues() and introducing a colour profile:

WPF使用颜色模型的方式是System.Windows.Media.Color的静态构造函数FromValues()并引入颜色配置文件:

The following code, for example:

以下代码,例如:

var c = Color.FromValues(
               new float[] {1.0f,0.0f,0.0f,0.0f } , 
               new Uri("file://C:/ICCProfile.icc",  UriKind.Absolute));

creates a 100% Cyan colour.

创造100%青色。

Profiles can be downloaded from http://www.eci.org/doku.php?id=en:start

个人资料可以从http://www.eci.org/doku.php?id=en:start下载

I tested this solution with XpsDocumentWriter and I confirm that it creates the correct CMYK colour code.

我用XpsDocumentWriter测试了这个解决方案,并确认它创建了正确的CMYK颜色代码。

For XAML it is just the matter of building an IValueConverter that converts something like "~C,M,Y,K" (as #RRGGBB for RGB) to a real CMYK colour.

对于XAML,只需要构建一个IValueConverter,将“~C,M,Y,K”(如RGB的#RRGGBB)转换为真正的CMYK颜色。

#1


7  

OK again! It turned out to be much more easier than what I though: CMYK is directly usable in XAML:

好了!事实证明它比我更容易:CMYK可直接在XAML中使用:

<Grid Background="ContextColor file://C:/WINDOWS/system32/spool/drivers/color/EuroscaleCoated.icc 1.0,0.0,0.0,1.0,1.0">

#2


6  

OK! I found the answer:

好!我找到了答案:

The way that WPF uses colour models is by System.Windows.Media.Color's static constructor FromValues() and introducing a colour profile:

WPF使用颜色模型的方式是System.Windows.Media.Color的静态构造函数FromValues()并引入颜色配置文件:

The following code, for example:

以下代码,例如:

var c = Color.FromValues(
               new float[] {1.0f,0.0f,0.0f,0.0f } , 
               new Uri("file://C:/ICCProfile.icc",  UriKind.Absolute));

creates a 100% Cyan colour.

创造100%青色。

Profiles can be downloaded from http://www.eci.org/doku.php?id=en:start

个人资料可以从http://www.eci.org/doku.php?id=en:start下载

I tested this solution with XpsDocumentWriter and I confirm that it creates the correct CMYK colour code.

我用XpsDocumentWriter测试了这个解决方案,并确认它创建了正确的CMYK颜色代码。

For XAML it is just the matter of building an IValueConverter that converts something like "~C,M,Y,K" (as #RRGGBB for RGB) to a real CMYK colour.

对于XAML,只需要构建一个IValueConverter,将“~C,M,Y,K”(如RGB的#RRGGBB)转换为真正的CMYK颜色。