C#
  Home arrow C# arrow Color Transformation Applications in C# GD...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

Color Transformation Applications in C# GDI+ Programming
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2008-07-30

    Table of Contents:
  • Color Transformation Applications in C# GDI+ Programming
  • Pulling Out the Foreground Image Demo
  • About the Color Channel
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Color Transformation Applications in C# GDI+ Programming


    (Page 1 of 4 )

    In this last installment of the series related to color transformation in GDI+, we will delve into two typical types of color transformation applications: one is color remapping and the other is color channel isolating.

    Now, let’s start with what color remapping is and how we can use it in real scenarios.

    Color Remapping

    As far as color mapping is concerned, the commonly-used color palette under the GDI environment may come to mind. By adjusting the standard colors via the color palette, we can redefine the values of the color indexes in the color palette. A typical application is the fading in and out effects with an image via the color palette technique. However, the color palette can only be utilized when the number of the colors is less than 256. When the number of the colors on the screen is greater than 256, the color palette technique can no longer take effect. GDI+ introduces a new form of ‘color remapping’ that redefines the specified colors. It is mainly based on the idea of the color palette,

    In GDI+, the colors of an image can be adjusted when they are rendered according to the facts of the requests. The key to achieving this result is to redefine the colors, i.e. color remapping. In fact, color remapping is the process of converting the colors in an image according to a color remap table, which, in fact, is an array of ColorMap structures. Each ColorMap structure in the array has an oldColor member and a newColor member.

    Let’s consider the following typical scenario. During the course of making a television program, the background color is generally set blue. In this case, when the background needs to be changed or the videos need to be synthesized, the blue color in the background can be weeded out so as to maintain the main picture. Based on this, let’s consider how to weed out the background color of an image.

    The commonly-used solution to solve the above problem is to replace the background color with a transparent color. In fact, GDI+ has introduced a class named ColorMap to perform this function, where some kind of color redirection relation is defined. Furthermore, we can substitute any of the other colors in the image using ColorMap.

    When GDI+ draws an image, each pixel of the image is compared to the array of old colors. If a pixel's color matches an old color, its color is changed to the corresponding new color. The colors are changed only for rendering—the color values of the image itself (stored in an Image or Bitmap object) are not changed.

    To draw a remapped image, initialize an array of ColorMap structures. Pass the address of that array to the SetRemapTable method of an ImageAttributes object, and then pass the address of the ImageAttributes object to the Graphics::DrawImage method of a Graphics object.

    Let’s examine several signatures of the SetRemapTable method in detail.

    public void SetRemapTable (ColorMap[] map);

    public void SetRemapTable ( ColorMap[] map,ColorAdjustType type);

    For easy use, let’s also list the definition of the ColorMap class disassembled using Luts Roeder’s .NET Reflector:

    public sealed class ColorMap

    {

    // Fields

    private Color newColor = new Color();

    private Color oldColor = new Color();

    // Properties

    public Color NewColor

    {

    get

    {

    return this.newColor;

    }

    set

    {

    this.newColor = value;

    }

    }

    public Color OldColor

    {

    get

    {

    return this.oldColor;

    }

    set

    {

    this.oldColor = value;

    }

    }

    }

    Now let's construct a sample application that pulls the foreground Image object out of the original image named Nemo_Blue.bmp.

    More C# Articles
    More By Xianzhong Zhu


     

    C# ARTICLES

    - Cyclic Redundancy Check
    - Handling Methods and Functions
    - Destroying Objects in C#
    - Creating Objects in C-Sharp
    - Classes and Objects
    - Programming Languages: Managed versus Native
    - LINQ-to-MySQL with DbLinq in C#
    - Working with Dates and Times in C#
    - Generics, Dictionaries, and More
    - More About Generics
    - Working with C# Collections
    - Generics
    - C# and XML
    - Pointers and Arrays in C#
    - C# 3.0 Extension Methods





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT