Creating, Viewing, and Merging Color Separations (Visual Basic)

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. image\btncmd.gif Select the CommandButton 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.

3. In the Properties box, change the CommandButton control's Caption property to Do Separations.

4. Add the following code to the CommandButton control's Click procedure. In online help, you can use the Edit pull-down menu to copy the block of code.

Sub Command6_Click ()

' Count the button clicks and take the next step with each click
Static ClickCount As Integer
MousePointer = 11 ' hourglass
'Turn off the automatic display rectangles.
Lead1.AutoSetRects = False

Select Case ClickCount
Case 0
    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

    Msg = "Separated. Keep clicking to see separations, then merge"
    MsgBox Msg
Case 1
    Lead1.Bitmap = Lead1.ColorPlanes(0) 'Cyan
    Lead1.ForceRepaint
Case 2
    Lead1.Bitmap = Lead1.ColorPlanes(1) ' Magenta
    Lead1.ForceRepaint
Case 3
    Lead1.Bitmap = Lead1.ColorPlanes(2) ' Yellow
    Lead1.ForceRepaint
Case 4
    Lead1.Bitmap = Lead1.ColorPlanes(3) ' K
    Lead1.ForceRepaint
Case 5
    Lead1.ColorMerge COLORSEP_CMYK
    Lead1.ForceRepaint
    Lead1.ColorPlanes(0) = 0
    Lead1.ColorPlanes(1) = 0
    Lead1.ColorPlanes(2) = 0
    Lead1.ColorPlanes(3) = 0
    Msg = "Merged, with more contrast in the K plane"
    MsgBox Msg
Case Else
    ClickCount = -1
    Msg = "Cycle is finished"
    MsgBox Msg
End Select

ClickCount = ClickCount + 1
MousePointer = 0 ' default

End Sub

5. 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.