Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - More Examples of Simplified Image Processi...
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

More Examples of Simplified Image Processing in GDI+
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2008-09-17

    Table of Contents:
  • More Examples of Simplified Image Processing in GDI+
  • Sample Six-Working with Thumbnail Images
  • Sample Seven-Cloning an Image
  • Sample Eight-Zooming in and out

  • 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


    More Examples of Simplified Image Processing in GDI+ - Sample Eight-Zooming in and out


    (Page 4 of 4 )

    In this sample, we will continue to work with the DrawImage() function, but to achieve the zooming in and out effect. First, let us quickly examine the signature of this function, as follows:

    // Summary:

    // Draws the specified portion of the specified System.Drawing.Image at the

    // specified location and with the specified size.

    // Parameters:

    // image:

    // System.Drawing.Image to draw.

    // destRect:

    // System.Drawing.Rectangle structure that specifies the location and size of

    // the drawn image. The image is scaled to fit the rectangle.

    // srcX:

    // The x-coordinate of the upper-left corner of the portion of the source image

    // to draw.

    // srcY:

    // The y-coordinate of the upper-left corner of the portion of the source image

    // to draw.

    // srcWidth:

    // Width of the portion of the source image to draw.

    // srcHeight:

    // Height of the portion of the source image to draw.

    // srcUnit:

    // Member of the System.Drawing.GraphicsUnit enumeration that specifies the

    // units of measure used to determine the source rectangle.

    // Exceptions:

    // System.ArgumentNullException:

    // image is null.

    public void DrawImage(Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit);

    Note that the source area and the target area of the DrawImage() function are irrelevant. If the source area is bigger the target area, invoking the DrawImage() function will result in a zooming out result; otherwise, we will see a converse zooming in effect. Now, let us start to write the application whose crucial code is listed below:

    Graphics graphics=this.CreateGraphics();

    graphics.Clear(Color.White);

    //load the image

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

    //define the area to show the image

    Rectangle rect=new Rectangle(0,0,image.Width,image.Height);

    graphics.DrawImage(image,rect);


    //set the size of the zooming out area to 80*80

    graphics.TranslateTransform(image.Width+10,0);

    Rectangle smallrect=new Rectangle(0,0,80,80);

    //zooming out effect

    graphics.DrawImage(image,smallrect,80,10,106,112,GraphicsUnit.Pixel);


    graphics.TranslateTransform(0,100);

    //set the size of the zooming in area to 80*80

    Rectangle largerect=new Rectangle(0,0,80,80);

    //zooming in effect

    graphics.DrawImage(image,largerect,56,101,35,40,GraphicsUnit.Pixel);

    Now, press F5 to launch this sample, and you will see the running time snapshot as shown in Figure 9.


    Figure 9-the running time snapshot to achieve the zooming in and out effects

    Apparently, in Figure 9, the head of Gandalf is zoomed out, while the head of Aragorn is zoomed in. Regrettably, herein we have only utilized the hard-code means. However, if you continue to add mouse dragging to select certain shapes to zoom into or out from your target, that would be better.

    Summary

    The two most important classes in GDI+ are Image and Bitmap; they greatly simplify image processing. Moreover, to handle a Metafile file it is highly recommended that you fall back on the Metafile class. By leveraging several interpolating algorithms, you can easily control the different kinds of rendering qualities. At last, we've discussed the GetThumbnailImage() method as well as Clone() to achieve other kinds of special image effects.


    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.

     

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