Windows Scripting
  Home arrow Windows Scripting arrow Page 5 - Simplified Image Processing in GDI+
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? 
WINDOWS SCRIPTING

Simplified Image Processing in GDI+
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating:  stars stars stars stars stars / 0
    2008-09-10

    Table of Contents:
  • Simplified Image Processing in GDI+
  • Meta File Support in GDI
  • Sample One-Record and Replay Metafiles
  • Sample Two-Clipping and Scaling Images
  • Sample Three-Use Interpolation to Output
  • Sample Four-Flipping an Image

  • 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


    Simplified Image Processing in GDI+ - Sample Three-Use Interpolation to Output


    (Page 5 of 6 )

    Different Qualities of Images

    What is interpolation? Interpolation is a kind of mathematic algorithm to compute the middle value of two given endpoints.

    In GDI+ you can use Interpolation to adjust the rendering quality of an image. If you want to stretch an image, you have to map each of the pixels in the source image to the corresponding pixel in the larger target one, while achieving a shrink effect requires similar mapping with the smaller target image. As you may image, the selected mapping algorithm will decide the result of the rendered image. To gain better quality requires longer processing time.

    An enumeration type, InterpolationMode, is defined in GDI+ to control the different interpolation modes. The following table lists all the values associated with InterpolationMode.


    Member name

    Description

    Invalid

    Equivalent to the Invalid element of the QualityMode enumeration.

    Default

    Specifies default mode.

    Low

    Specifies low quality interpolation.

    High

    Specifies high quality interpolation.

    Bilinear

    Specifies bilinear interpolation. No prefiltering is done. This mode is not suitable for shrinking an image below 50 percent of its original size.

    Bicubic

    Specifies bicubic interpolation. No prefiltering is done. This mode is not suitable for shrinking an image below 25 percent of its original size.

    NearestNeighbor

    Specifies nearest-neighbor interpolation.

    HighQualityBilinear

    Specifies high-quality, bilinear interpolation. Prefiltering is performed to ensure high-quality shrinking.

    HighQualityBicubic

    Specifies high-quality, bicubic interpolation. Prefiltering is performed to ensure high-quality shrinking. This mode produces the highest quality transformed images.


    Now let's look at a sample to see how you can use the different interpolation modes to affect rendering quality. Figure 3 illustrates the running-time snapshot for sample 3, through which you can apparently notice from the head and feature parts of the eagle that different modes of interpolation result in different rendering quality.


    Figure 3-the running-time snapshot for sample 3

    You can find the final answer in the following code:

    private void UsingInterpolationMode_Click(object sender, System.EventArgs e)

    {

    Graphics graphics=this.CreateGraphics();

    graphics.Clear(Color.White);


    //load the image

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

    int width = image.Width;

    int height = image.Height;


    //draw the source image

    graphics.DrawImage(

    image,

    new Rectangle(0, 0, width, height), //target area

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

    width, //width of the source image

    height, //height of the source image

    GraphicsUnit.Pixel);


    //shift to drawing plane to the right

    graphics.TranslateTransform( width+10,0);

    //use NearestNeighbor (low quality)

    graphics.InterpolationMode=InterpolationMode.NearestNeighbor;

    graphics.DrawImage(

    image,

    new RectangleF(0.0f, 0.0f, 0.6f * width, 0.6f * height), //target area

    new RectangleF(0, 0, //upper left corner of the source image

    width, //width of the source image

    height), //height of the source image

    GraphicsUnit.Pixel);


    //shift to drawing plane to the right

    graphics.TranslateTransform( 0.6f*width+10,0);

    // use Bicubic mode (high quality)

    graphics.InterpolationMode=InterpolationMode.Bicubic;

    graphics.DrawImage(

    image,

    new RectangleF(0, 0, 0.6f * width, 0.6f * height), //target area

    new Rectangle(0, 0, //upper left corner of the source image

    width, //width of the source image

    height), //height of the source image

    GraphicsUnit.Pixel);


    //shift to drawing plane to the right

    graphics.TranslateTransform(0.6f*width+10,0f);

    // use the highest quality of HighQualityBicubic mode

    graphics.InterpolationMode=InterpolationMode.HighQualityBicubic;

    graphics.DrawImage(

    image,

    new RectangleF(0, 0, 0.6f * width, 0.6f * height), //target area

    new Rectangle(0, 0, //upper left corner of the source image

    width, //width of the source image

    height), //height of the source image

    GraphicsUnit.Pixel);

    }

    There is also one point worth noticing: different modes of interpolation will exhaust different quantities of system resources. And from Figure 3 above you will have concluded that the HighQualityBicubic mode of interpolation will consume the most system resources, which of course corresponds to the slowest rendering speed.

    More Windows Scripting Articles
    More By Xianzhong Zhu


     

    WINDOWS SCRIPTING ARTICLES

    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...
    - Modifying XML Files in WSH
    - Reading XML Files in WSH
    - Visual Basic 2005 XML Programming Using XML ...
    - Creating an XML Document in WSH
    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH

     
    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