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:
In the "Solution Explorer" window, right-click 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 "<LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32 " folder and select the following DLLs:
Click the Select button and then press the OK button to add the above DLLs to the application.
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:
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.Controls.WinFormsImports Leadtools.ImageProcessing.Color
using Leadtools;using Leadtools.Codecs;using Leadtools.Controls.WinForms;using Leadtools.ImageProcessing.Color;
Add an event handler to the Form1 Load event and add the following code:
' To keep track of what step in the tutorial we arePrivate clicksCount As IntegerPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load' initialize a new RasterCodecs objectDim codecs As New RasterCodecs' load the main image into our viewerRasterImageViewer1.Image = codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp")Label1.Text = "Click to separate this image into CMYK components"End Sub
// To keep track of what step in the tutorial we areprivate int clicksCount;private void Form1_Load(object sender, System.EventArgs e){// initialize a new RasterCodecs objectRasterCodecs codecs = new RasterCodecs();// load the main image into our viewerrasterImageViewer1.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp");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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickSelect Case (clicksCount)Case 0' Separate the image into 4 images based on the CMYK color spaceDim seperateCommand As New ColorSeparateCommandseperateCommand.Type = ColorSeparateCommandType.CmykseperateCommand.Run(RasterImageViewer1.Image)' put this new image (4 pages, 1 for each component) in the viewerRasterImageViewer1.Image = seperateCommand.DestinationImageLabel1.Text = "C component"Case 1' View the second page that represents the M componentRasterImageViewer1.Image.Page = 2Label1.Text = "M component"Case 2' View the third page that represents the Y componentRasterImageViewer1.Image.Page = 3Label1.Text = "Y component"Case 3' View the forth page that represents the K componentRasterImageViewer1.Image.Page = 4Label1.Text = "K component"Case 4' Merge the 4 images to get the original image again, and reset the clickCount so the user can perform the entire process again.Dim mergeCommand As New ColorMergeCommand(ColorMergeCommandType.Cmyk)mergeCommand.Run(RasterImageViewer1.Image)RasterImageViewer1.Image = mergeCommand.DestinationImageLabel1.Text = "Image colors have been merged again. Click to separate this image into CMYK components"clicksCount = -1End SelectclicksCount = clicksCount + 1End Sub
private void button1_Click(object sender, System.EventArgs e){switch(clicksCount){case 0:// Separate the image into 4 images based on the CMYK color spaceColorSeparateCommand seperateCommand = new ColorSeparateCommand();seperateCommand.Type = ColorSeparateCommandType.Cmyk;seperateCommand.Run(rasterImageViewer1.Image);// put this new image (4 pages, 1 for each component) in the viewerrasterImageViewer1.Image = seperateCommand.DestinationImage;label1.Text = "C component";break;case 1:// View the second page that represents the M componentrasterImageViewer1.Image.Page = 2;label1.Text = "M component";break;case 2:// View the third page that represents the Y componentrasterImageViewer1.Image.Page = 3;label1.Text = "Y component";break;case 3:// View the forth page that represents the K componentrasterImageViewer1.Image.Page = 4;label1.Text = "K component";break;case 4:// Merge the 4 images to get the original image again, and reset the clickCount so the user can perform the entire process again.ColorMergeCommand mergeCommand = new ColorMergeCommand(ColorMergeCommandType.Cmyk);mergeCommand.Run(rasterImageViewer1.Image);rasterImageViewer1.Image = mergeCommand.DestinationImage;label1.Text = "Image colors have been merged again. Click to separate this image into CMYK components";clicksCount = -1;break;}clicksCount++;}
Build, and Run the program to test it. NOTE: If you encounter an "Invalid File Format" or "Feature Not Supported" exception, refer to the Invalid File Format/Feature Not Supported topic.
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
