Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>You can approximate a conversion between the <a href="http://en.wikipedia.org/wiki/RGB_color_model" rel="nofollow">RGB</a> and <a href="http://en.wikipedia.org/wiki/CMYK_color_model" rel="nofollow">CMYK</a> color spaces, but it's not going to be completely accurate or bidirectional.</strong> There are numerous differences between the two color spaces that become relevant here, including their respective gamuts (see the diagram in oezi's answer), the additive vs. subtractive models, and the presence of black (key) in the CMYK space.</p> <p>If you're merely interested in a simple way to convert a color from its RGB to CMYK representation, you can use the following code (arbitrarily in C#; feel free to convert to the language of your choice):</p> <pre><code>public CmykColor RgbToCmyk(int R, int G, int B) { if ((R &lt; 0) || (R &gt; 255) || (G &lt; 0) || (G &gt; 255) || (B &lt; 0) || (B &gt; 255)) { throw new ArgumentException("RGB values must be in the range of 0 to 255"); } if ((R == 0) &amp;&amp; (G == 0) &amp;&amp; (B == 0)) { return new CmykColor(0, 0, 0, 1); } else { double calcR = 1 - (R / 255); double calcG = 1 - (G / 255); double calcB = 1 - (B / 255); double K = Math.Min(calcR, Math.Min(calcG, calcB)); double C = (calcR - K) / (1 - K); double M = (calcG - K) / (1 - K); double Y = (calcB - K) / (1 - K); return new CmykColor(Convert.ToInt32(C), Convert.ToInt32(M), Convert.ToInt32(Y), Convert.ToInt32(K)); } } </code></pre> <p>But you'll have to decide if this simple approximation will produce results that are "close enough" for your needs. <strong>The most important thing to realize is that a true conversion is entirely dependent upon the physical device/process and requires accurately calibrated color profiles for each of your devices (the monitor displaying the RGB, the printer printing the CMYK, and the substrate receiving the CMYK).</strong></p> <p>This helps to explain why the above algorithm (or any other that you might implement on your own) is never going to match the results returned by Photoshop, which uses color profiles and some additional proprietary algorithms to handle its conversion. If this degree of accuracy is truly important, you could consider using something like the <a href="http://msdn.microsoft.com/en-us/library/dd372446%28v=VS.85%29.aspx" rel="nofollow">Windows Color Management APIs</a> to handle the conversion for you, which will automatically apply the current color profile, but you'll likely find that those results don't exactly match Photoshop's either.</p> <p><strong>The bottom line is that color is subjective.</strong> As I mentioned in the beginning, <strong>even if you overcome the accuracy hurdle, you will still not have a conversion process that is bidirectional.</strong> Even in Photoshop, you can't convert an image from RGB to CMYK and then back again without losing or altering some of the color information.</p> <hr> <p><strong>EDIT:</strong> You mention a couple of times in your comments that you just want "RGB values in percentage." I assume that this means <em>CMYK</em> percentages, but I suppose that it's worth pointing out if you just want to convert the standard 0-255 values for RGB components to an <em>RGB</em> percentage, you can just divide each value by 255 (the max), and then multiply by 100. So, for example:</p> <blockquote> <p>Red = RGB(255, 0, 0) = 100% Red, 0% Green, 0% Blue</p> <p>DarkSeaGreen = RGB(143, 188, 143) = 56% Red, 74% Green, 56% Blue</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload