You are here:About>Computing & Technology>Delphi Programming> Coding Delphi Applications> Delphi Tips and Tricks> Delphi 2007 Tips> Convert RGB Color to CMYK using Delphi
About.comDelphi Programming
Newsletters & RSSEmail to a friendSubmit to Digg

Convert RGB Color to CMYK

From Zarko Gajic,
Your Guide to Delphi Programming.
FREE Newsletter. Sign Up Now!

Programmatically using Delphi code

The CMYK (Cyan, Magenta, Yellow, Black - Key Plate) model, refers to the 4 ink colors used by the printing press. C is cyan (blue-green), M is magenta (pinkish shade of red), Y is yellow, and K is black, the key plate or keyline color.

The RGB (Red, Green, Blue) is also used, primarily in web design. When written, RGB values are commonly specified using three integers between 0 and 255, each representing red, green, and blue intensities.

Converting RGB images to CMYK is often one of the final steps before sending an image to a commercial printer.

Here's a function to convert a RGB color to a CMYK color.

uses Math;

function RGBtoCMYK(const rgbColor : TRGBColor) : TCMYKColor;
begin
  with Result do
  begin
    Cyan := 1 - rgbColor.Red;
    Magenta := 1 - rgbColor.Green;
    Yellow := 1 - rgbColor.Blue;

    KeyPlate := Min(Min(Cyan, Magenta), Yellow) ;

    Cyan := Cyan - KeyPlate;
    Magenta := Magenta - KeyPlate;
    Yellow := Yellow - KeyPlate;
  end;
end;
Usage:
var
  rgbColor : TRGBColor;
  cmykColor : TCMYKColor;
begin
  rgbColor.Red := 128;
  rgbColor.Green := 64;
  rgbColor.Blue := 192;

  cmykColor := RGBtoCMYK(rgbColor) ;

  Caption := Format('%d-%d-%d-%d',[cmykColor.Cyan, cmykColor.Magenta, cmykColor.Yellow, cmykColor.KeyPlate])
end;
Delphi tips navigator:
» Set the Checked property of a TCheckBox Delphi control Without raising the OnClick event
« An Invalid Hard-Cast is NIL in Delphi for .NET
 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.