Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming

Convert RGB Color to CMYK

Programmatically using Delphi code

By Zarko Gajic, About.com

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
More Delphi Programming Quick Tips
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Delphi Programming

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2007 Tips
  7. Convert RGB Color to CMYK using Delphi

©2009 About.com, a part of The New York Times Company.

All rights reserved.