Converts RGB to CMYK - CSharp System.Drawing

CSharp examples for System.Drawing:Color Convert

Description

Converts RGB to CMYK

Demo Code


using System.Drawing;
using System;//from  ww  w  . ja  va2s  . c  om

public class Main{
        /// <summary>
      /// Converts RGB to CMYK
      /// </summary>
      /// <param name="c">A color to convert.</param>
      /// <returns>A CMYK object</returns>
      public static CMYK RGB_to_CMYK(Color c)
      {
         CMYK _cmyk = new CMYK();
         double low = 1.0;

         _cmyk.C = (double)(255 - c.R)/255;
         if ( low > _cmyk.C )
            low = _cmyk.C;

         _cmyk.M = (double)(255 - c.G)/255;
         if ( low > _cmyk.M )
            low = _cmyk.M;

         _cmyk.Y = (double)(255 - c.B)/255;
         if ( low > _cmyk.Y )
            low = _cmyk.Y;

         if ( low > 0.0 )
         {
            _cmyk.K = low;
         }

         return _cmyk;
      }
}

Related Tutorials