C#
  Home arrow C# arrow Page 2 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 4
    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 - Pulling Out the Foreground Image Demo


    (Page 2 of 4 )

    In this sample, the code creates a color remap table that consists of a single ColorMap structure. The oldColor member of the ColorMap structure is blue and the newColor member is white. The image is drawn once without remapping and once with remapping. This will help us indirectly pull the foreground image out of the original one. The remapping process changes all the blue pixels to white.

    Take a look at the running-time snapshot, as is shown in Figure 1.


    Figure 1—the running-time snapshot

    Apparently, the right image in Figure 1 corresponds to the one in which the blue background is cleared away after the color remapping. 

    Look more carefully at the associated programming:

    Graphics graphics = this.CreateGraphics();

    graphics.Clear(Color.White);


    //load the original image with blue background

    Bitmap image = new Bitmap("Nemo_Blue.bmp");

    ImageAttributes imageAttributes = new ImageAttributes();


    int width = image.Width;

    int height = image.Height;

    //substitute blue for white to achieve the expected aim

    ColorMap colorMap = new ColorMap();

    colorMap.OldColor = Color.FromArgb(255, 0, 0, 255);

    colorMap.NewColor = Color.FromArgb(255, 255, 255, 255);

    //set up color remapping table

    ColorMap[] remapTable = { colorMap };


    //set up the color info for the image

    imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

    //render the source image

    graphics.DrawImage(image, 50, 50, width, height);

    //render the new image with the background color weeded out

    graphics.DrawImage(image,

    new Rectangle(width + 80, 50, width, height), //target rectangle

    0, 0, // upper left corner of the source image

    width, // width of the source image

    height, // height of the source image

    GraphicsUnit.Pixel,

    //color info

    imageAttributes);

    Note that we’ve only built one ColorMap object, meaning we only execute the color remapping once. So, if you want to eleminate other colors you have to define more ColorMap objects and continue to apply the related color remapping.

    With the color remapping application discussed, let’s take a look at another use of color transformation — isolating the color channel.

    More C# Articles
    More By Xianzhong Zhu


     

    C# ARTICLES

    - 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
    - Overloading Operators in C#
    - Iterators and Nullable Types
    - Patterns and Iterators in C#
    - C# Exceptions
    - Methods in C#
    - Delegates and Events in C#
    - Advanced C#

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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