8

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

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

Some notes:

  1. The question is NOT about converting from CMYK to RGB but to use real CMYK
  2. 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"

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

el_shayan
  • 2,735
  • 4
  • 28
  • 42

2 Answers2

7

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

<Grid Background="ContextColor file://C:/WINDOWS/system32/spool/drivers/color/EuroscaleCoated.icc 1.0,0.0,0.0,1.0,1.0">
el_shayan
  • 2,735
  • 4
  • 28
  • 42
  • How do you programmatically get these CMYK values? It seems that we only have access to the converted RGB as well as scRGB values, and the profile uri. – Alireza Jan 26 '13 at 12:58
  • Figured it out myself: `Color.GetNativeColorValues()` – Alireza Jan 26 '13 at 13:06
  • Well, did you also print these to PDF? The created pdf file does not respect color channels, so for instance, black goes to PDF to all channels. Do you know anything about this? Even, if we create an XPS and print it to PDF, the result still uses all inks for black. – Alireza Apr 01 '13 at 12:26
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:

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.

Profiles can be downloaded from 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.

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.

el_shayan
  • 2,735
  • 4
  • 28
  • 42