Utilizzando colori CMYK in WPF / XAML
Domanda
C'è un modo per specificare CMYK i colori direttamente in un documento XAML?
anteponendo # carattere creerà colori RGB, ma come per specificare un colore CMYK?
Alcune note:
- La domanda è: non sulla conversione da CMYK a RGB, ma di utilizzare vera CMYK
- Lo scopo è quello di permettere generato XPS di documenti (utilizzando System.Windows.Xps.Packaging per esempio) vedere il colore CMYK e generare i codici colore come "ContextColor /swopcmykprofile.icc a, b, c, d, e" non come "#aarrggbb"
ho cercato di definire i colori CMYK utilizzando ColorContext senza alcun successo.
Soluzione
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">
Altri suggerimenti
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.