Using CMYK colors in WPF / XAML

Is it possible to specify CMYK colors directly in a XAML document?

with the # character prefix will create RGB colors, but how do I specify CMYK color?

Some notes:

  • The question is NOT about converting from CMYK to RGB, but for using real CMYK
  • The goal is to allow the generated XPS documents (for example, using System.Windows.Xps.Packaging) to see the color as CMYK and generate the color codes as "ContextColor / swopcmykprofile.icc a, b, c, d, e" not like "#aarrggbb"

I tried to define CMYK colors using ColorContext without any success.

+8
colors wpf xaml xps cmyk
source share
2 answers

OK again! This turned out to be much simpler than me: CMYK is directly used in XAML:

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

OK! I found the answer:

How WPF uses color models, this is System.Windows.Media.Color static constructor FromValues() and the introduction of a color 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 100% blue color.

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 generates the correct CMYK color code.

For XAML, it's just a matter of building an IValueConverter , which converts something like "~ C, M, Y, K" (like #RRGGBB for RGB) into CMYK real color.

+6
source share

All Articles