Creating, Viewing, and Merging Color Separations (Delphi)

Take the following steps to add code that creates CMYK color separations, displays each of the color planes, merges the planes, and displays the result. The code increases the contrast of the K plane to demonstrate how you can manipulate the color separations.

1.

Start with the project that you created in Loading and Displaying an Image.

2.

Add the following declaration to the private section of the Unit1 file:

ClickCount: Integer; {Used with the Color Separations example}

3.

image\btndbtn.gif Select the Button control; then add the control to your main form. Put the control at the top of the form to keep it away from the image.

4.

In the Object Inspector box, change the Button control's Caption property to Do Separations.

5.

Code the Do Separations button's Click procedure as follows. In online help, you can copy the block of code and paste it into your application.

procedure TForm1.Button1Click(Sender: TObject);

begin
Screen.Cursor := crHourglass;

{Turn off the automatic display rectangles.}
Lead1.AutoSetRects := False;

{Use the ClickCount form variable to step through the actions.}
If ClickCount = 0 then
begin
    Lead1.ColorSeparate(COLORSEP_CMYK);
    {Just for fun, add contrast to the K plane}
    Lead1.Bitmap := Lead1.ColorPlanes[3]; {Copy the K plane}
    Lead1.Contrast(300); {Increase the contrast}
    Lead1.ColorPlanes[3] := Lead1.Bitmap; {Update the K plane}
    ShowMessage('Separated. Keep clicking to see separations, then merge');
end;
if ClickCount = 1 then
begin
    Lead1.Bitmap := Lead1.ColorPlanes[0]; {Cyan}
    Lead1.ForceRepaint;
end;
if ClickCount = 2 then
begin
    Lead1.Bitmap := Lead1.ColorPlanes[1]; { Magenta}
    Lead1.ForceRepaint;
end;
if ClickCount = 3 then
begin
    Lead1.Bitmap := Lead1.ColorPlanes[2]; { Yellow}
    Lead1.ForceRepaint;
end;
if ClickCount = 4 then
begin
    Lead1.Bitmap := Lead1.ColorPlanes[3]; { K}
    Lead1.ForceRepaint;
end;
if ClickCount = 5 then
begin
    Lead1.ColorMerge(COLORSEP_CMYK);
    Lead1.ForceRepaint;
    Lead1.ColorPlanes[0] := 0;
    Lead1.ColorPlanes[1] := 0;
    Lead1.ColorPlanes[2] := 0;
    Lead1.ColorPlanes[3] := 0;
    ShowMessage('Merged, with more contrast in the K plane');
end;
if ClickCount = 6 then
begin
    ClickCount := -1;
    ShowMessage('Cycle is finished');
end;

ClickCount := ClickCount + 1;
Screen.Cursor := crDefault;
end;

6.

Run your program to test it. Notice that you can click the button several times to create the separations, view each of them, and merge them to recreate the original bitmap.