C#
  Home arrow C# arrow Page 4 - Performing Color Transformation Operations...
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#

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

    Table of Contents:
  • Performing Color Transformation Operations in C# GDI+
  • Scaling Color Operation
  • Rotating Color Operation
  • Shearing Color Operation

  • 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


    Performing Color Transformation Operations in C# GDI+ - Shearing Color Operation


    (Page 4 of 4 )

    Shearing increases or decreases a color component by an amount proportional to another color component. For example, consider the transformation where the red component is increased by one half the value of the blue component. Under such a transformation, the color (0.2, 0.5, 1) would become (0.7, 0.5, 1). The new red component is 0.2 + (1/2)(1) = 0.7. Herein, we say that the red component is a map to the blue component; or in another way, that the blue component is sheared to the red one. Figure 10 shows the color relations in the shearing color operation.


    Figure 10-the color components in gray join in the shearing transformation

    Now, let's continue to take a look at the related sample. The following example constructs an Image object from the file Colorinput.bmp. Then the code applies the shearing transformation described in the preceding paragraph to each pixel in the image.

    Graphics graphics=this.CreateGraphics();

    graphics.Clear(Color.White);

    //load the image

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

    ImageAttributes imageAttributes=new ImageAttributes();

    int width = image.Width;

    int height = image.Height;

    //define the color transformation matrix

    float[][] colorMatrixElements=

    {

    new float[]{1.0f, 0.0f, 0.0f, 0.0f, 0.0f},

    new float[]{0.0f, 1.0f, 0.0f, 0.0f, 0.0f},

    new float[]{0.5f, 0.0f, 1.0f, 0.0f, 0.0f},

    new float[]{0.0f, 0.0f, 0.0f, 1.0f, 0.0f},

    new float[]{ 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}

    };

    ColorMatrix colorMatrix=new ColorMatrix(colorMatrixElements);

    //enable the color transformation matrix

    imageAttributes.SetColorMatrix(

    colorMatrix,

    ColorMatrixFlag.Default,

    ColorAdjustType.Bitmap);

    //render the source image

    graphics.DrawImage(image, 0, 0);

    //use the color transformation matrix defined above to render new image

    graphics.TranslateTransform(width+10,0);

    graphics.DrawImage(image, new Rectangle(0, 0, width, height),

    0, 0,width, height,GraphicsUnit.Pixel,imageAttributes);

    In the code, the element at column 1 of row 3 of the color transformation matrix is set to 0.5, which means that during the shearing color transformation, all the increments of the red component are half of the blue component. The following illustration (Figure 11) shows the original image on the left and the newly-sheared one on the right.


    Figure 11-the running-time snapshot for the shearing transformation

    As is apparently shown in Figure 11, after the shearing operation the red components in the target image increase.

    Summary

    In this installment, we've thoroughly examined the four kinds of color operations(translating, scaling, rotating, and shearing) in GDI+ and come to realize that the four transformations are the fundamental operations of nearly all coloring support. In the third installment of this series, we will explore the color remapping support in GDI+, as well as try to achieve the effect of Photoshop-like color channel isolating via the color transformation matrices.

    -DOWNLOAD SOURCE-


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    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 5 hosted by Hostway
    Stay green...Green IT