Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

WPF Color Picker Construction Kit

, 26 Dec 2010
A WPF color picker (like Adobe's) constructed in a modular fashion for easy modification.
ColorPickerDemo.zip
ColorPickerSource.zip
ColorPickerDemo
ColorPicker
ColorModels
CMY
CMYK
HSB
Lab
RGB
ExtensionMethods
Properties
Settings.settings
Resources
ColorPickerControls
Chips
Dialogs
Pickers
Properties
Settings.settings
ColorPickerDemo
ColorPickerDemo.ico
Properties
Settings.settings
using System;
using System.Windows.Media;
using ColorPicker.ExtensionMethods;

namespace ColorPicker.ColorModels.CMYK
{
  public  class CMYKModel
  {


      #region Color

      public enum ECMYKComponent
      {
          Cyan = 0,
          Magenta = 1,
          Yellow = 2,
          Black =3
      }


      Color Color(double[] components)
      {
          return Color(components[0], components[1], components[2], components[3]);
      }

      public Color Color(double cyan, double magenta, double yellow, double black)
      {

          var red =   (255 - cyan - black  ).RestrictToByte()  ;
          var green = (255 - magenta - black).RestrictToByte();
          var blue =  (255 - yellow - black).RestrictToByte();
          return System.Windows.Media.Color.FromRgb( red, green, blue);

      }

       


      #endregion

      #region components

      private double MinComponent(Color color)
      {
          double c = 255 - color.R;
          double m = 255 - color.G ;
          double y = 255 - color.B;

         return   Math.Min(c, Math.Min(m, y));
      }

      public double CComponent(Color color , Double greedieness)
      {
          if (greedieness > 1 || greedieness < 0)
          {
              throw new Exception("Greedieness must be between 0 and 1");
          }
          var min = MinComponent(color);
          return 255 - color.R - min * greedieness ;
      }

      public double CComponent(Color color)
      {
          var min = MinComponent(color);
          return 255 - color.R - min;
      }

      public Double MComponent(Color color, Double greedieness)
      {
          if (greedieness > 1 || greedieness < 0)
          {
              throw new Exception("Greedieness must be between 0 and 1");
          }
          var min = MinComponent(color);
          return 255 - color.G - min*greedieness;
      }

      public Double MComponent(Color color)
      {
          var min = MinComponent(color);
          return 255 - color.G - min;
      }

      public Double YComponent(Color color, Double greedieness)
      {
          var min = MinComponent(color);
          return 255 - color.B - min * greedieness;
      }


      public Double YComponent(Color color)
      {
          var min = MinComponent(color);
          return 255 - color.B - min;
      }

      public Double KComponent(Color color, Double greedieness)
      {
          var min = MinComponent(color);
          return min*greedieness;  
      }


       public Double KComponent(Color color)
       {
           var min = MinComponent(color);
           return min;
       }

      #endregion
  }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

KenJohnson
Software Developer (Senior)
United States United States
Written software for what seems like forever. I'm currenly infatuated with WPF. Hopefully my affections are returned.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 26 Dec 2010
Article Copyright 2010 by KenJohnson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid