1. Computing & Technology

Discuss in my forum

Convert RGB Color to CMYK

Programmatically using Delphi code

By , About.com Guide

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

©2012 About.com. All rights reserved.

A part of The New York Times Company.