|   Title: Colorize images by remapping colors in C#
 ![[Colorize images by remapping colors in C#]](howto_colorize2.png)  
This example is an extension of the example Colorize images in C#. The new version of the program provides two new menus, Swap and Remap.
 
 
Swap
Red/Green
Red/Blue
Green/Blue
Remap
Red to Yellow
Red to Orange
Red to Fuchsia
Red to White
Red to Black
 
These menu commands place predefined values in the color matrix text boxes. For example, the following code shows how the Remap > Red to Fuchsia command works.
 
 private void mnuRedToFuchsia_Click(object sender, EventArgs e)
{
    MakeIdentity();
    TextBoxes[0][0].Text = "1.3000";
    TextBoxes[0][2].Text = "1.3000";
    TextBoxes[1][1].Text = "0.5000";
    TextBoxes[2][2].Text = "0.0000";
    ColorPicture();
} 
The call to MakeIdentity the text boxes to form an identity matrix. (Zeros everywhere except the diagonal, which contains ones.) It then sets the following entries to new values.
 
 
TextBoxes[0][0]: Makes the red component equal 1.3 times its original value
TextBoxes[0][2]: Makes the blue component equal 1.3 times the original red component value
TextBoxes[1][1]: Makes the green component equal 0.5 times its original value
TextBoxes[2][2]: Removes the original blue component value
 
The other menu commands work similarly.
 
I only implemented these commands because those are the only ones I needed for my current project, but it would be easy enough to add similar commands to perform other color manipulations. For example, you could add a Green to Orange command. 
Download the example to experiment with it and to see additional details.
           |