Creating, Viewing, and Merging Color Separations (Visual J++)

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

3. In the Properties box, change the Button control's Text property to Do Separations.

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

// Count the button clicks and take the next step with each click
private int m_nClickCount = 0;

private void button1_click(Object source, Event e)
{
   setCursor( Cursor.WAIT );  // hourglass

   // Turn off the automatic display rectangles.
   LEAD1.setAutoSetRects( false );

   switch( m_nClickCount )
   {
      case 0 :
         LEAD1.ColorSeparate( (short) LTOCXU.ColorSeparationConstants.COLORSEP_CMYK );

         // Just for fun, add contrast to the K plane
         LEAD1.setBitmap( LEAD1.getColorPlanes( (short) 3 ) );  // Copy the K plane
         LEAD1.Contrast( (short) 300 );  // Increase the contrast
         LEAD1.setColorPlanes( (short) 3, LEAD1.getBitmap() );  //Update the K plane

         MessageBox.show( "Separated. Keep clicking to see separations, then merge" );
         break ;

      case 1 :
         LEAD1.setBitmap( LEAD1.getColorPlanes( (short) 0 ) );  // Cyan
         LEAD1.ForceRepaint();
         break ;

      case 2 :
         LEAD1.setBitmap( LEAD1.getColorPlanes( (short) 1 ) );  // Magenta
         LEAD1.ForceRepaint();
         break ;

      case 3 :
         LEAD1.setBitmap( LEAD1.getColorPlanes( (short) 2 ) );  // Yellow
         LEAD1.ForceRepaint();
         break; 

      case 4 :
         LEAD1.setBitmap( LEAD1.getColorPlanes( (short) 3 ) );  // K
         LEAD1.ForceRepaint();
         break; 

      case 5 :
         LEAD1.ColorMerge( (short) LTOCXU.ColorSeparationConstants.COLORSEP_CMYK );
         LEAD1.ForceRepaint();
         LEAD1.setColorPlanes( (short) 0, 0 );
         LEAD1.setColorPlanes( (short) 1, 0 );
         LEAD1.setColorPlanes( (short) 2, 0 );
         LEAD1.setColorPlanes( (short) 3, 0 );
         MessageBox.show( "Merged, with more contrast in the K plane" );
         break ;

      default :
         m_nClickCount = -1;
         MessageBox.show( "Cycle is finished" );
   }

   m_nClickCount++;
   setCursor( Cursor.DEFAULT );  // default
}

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.