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:
Start Visual Studio .NET. Choose File->New->Project… from the menu. In the New Project dialog box, choose either "Visual C# Projects" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application " in the Templates List. Type the project name as "Separate and Merge Image Colors" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK. In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "\LEAD Technologies\LEADTOOLS 15\Bin\DotNet\Win32 " folder and select the following DLLs: Leadtools.dll Leadtools.Codecs.dll Leadtools.WinForms.dll
Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and Drag and drop an instance of RasterImageViewer to the form. If you do not have RasterImageViewer in your toolbox, select Tools->Add Remove Toolbox Items from the menu. Click Browse and then select Leadtools.WinForms.DLL from "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Bin\DotNet\Win32" and then click Open and then click OK. From the toolbox (View->Toolbox), add a Button control (text = "Next") and a Label control to the form. Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file: [Visual Basic]
[C#]Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.WinForms Imports Leadtools.ImageProcessing.Color
using Leadtools; using Leadtools.Codecs; using Leadtools.WinForms; using Leadtools.ImageProcessing.Color;
Add an event handler to the Form1 Load event and add the following code: [Visual Basic]
[C#]' To keep track of what step in the tutorial we are Private clicksCount As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load RasterCodecs.Startup() ' intitialize a new RasterCodecs object Dim codecs As New RasterCodecs ' load the main image into our viewer RasterImageViewer1.Image = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp") RasterCodecs.Shutdown(); Label1.Text = "Click to separate this image into CMYK components" End Sub
// To keep track of what step in the tutorial we are private int clicksCount; private void Form1_Load(object sender, System.EventArgs e) { RasterCodecs.Startup(); // intitialize a new RasterCodecs object RasterCodecs codecs = new RasterCodecs(); // load the main image into our viewer rasterImageViewer1.Image = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp"); RasterCodecs.Shutdown(); label1.Text = "Click to separate this image into CMYK components"; }
double-click the button1 Button on the form to add the event handler for it and add the following code: Build, and Run the program to test it. [Visual Basic]
[C#]Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Select Case (clicksCount) Case 0 ' Seperate the image into 4 images based on CMYK color space Dim seperateCommand As New ColorSeparateCommand seperateCommand.Type = ColorSeparateCommandType.Cmyk seperateCommand.Run(RasterImageViewer1.Image) ' put this new image (4 pages, 1 for each component) in the viewer RasterImageViewer1.Image = seperateCommand.DestinationImage Label1.Text = "C component" Case 1 ' View the second page that represent M component RasterImageViewer1.Image.Page = 2 Label1.Text = "M component" Case 2 ' View the third page that represent Y component RasterImageViewer1.Image.Page = 3 Label1.Text = "Y component" Case 3 ' View the forth page that represent K component RasterImageViewer1.Image.Page = 4 Label1.Text = "K component" Case 4 ' Merge the 4 images to get the orignal image again, and reset the clickCount so the user can make do whole process again. Dim mergeCommand As New ColorMergeCommand(ColorMergeCommandType.Cmyk) mergeCommand.Run(RasterImageViewer1.Image) RasterImageViewer1.Image = mergeCommand.DestinationImage Label1.Text = "Image colors has been merged again. Click to separate this image into CMYK components" clicksCount = -1 End Select clicksCount = clicksCount + 1 End Sub
private void button1_Click(object sender, System.EventArgs e) { switch(clicksCount) { case 0: // Seperate the image into 4 images based on CMYK color space ColorSeparateCommand seperateCommand = new ColorSeparateCommand(); seperateCommand.Type = ColorSeparateCommandType.Cmyk; seperateCommand.Run(rasterImageViewer1.Image); // put this new image (4 pages, 1 for each component) in the viewer rasterImageViewer1.Image = seperateCommand.DestinationImage; label1.Text = "C component"; break; case 1: // View the second page that represent M component rasterImageViewer1.Image.Page = 2; label1.Text = "M component"; break; case 2: // View the third page that represent Y component rasterImageViewer1.Image.Page = 3; label1.Text = "Y component"; break; case 3: // View the forth page that represent K component rasterImageViewer1.Image.Page = 4; label1.Text = "K component"; break; case 4: // Merge the 4 images to get the orignal image again, and reset the clickCount so the user can make do whole process again. ColorMergeCommand mergeCommand = new ColorMergeCommand(ColorMergeCommandType.Cmyk); mergeCommand.Run(rasterImageViewer1.Image); rasterImageViewer1.Image = mergeCommand.DestinationImage; label1.Text = "Image colors has been merged again. Click to separate this image into CMYK components"; clicksCount = -1; break; } clicksCount++; }
Build, and Run the program to test it.