Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - 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 One-Record and Replay Metafiles


    (Page 3 of 6 )

    As is indicated above, to record a meta file is in fact to persist all the drawing instructions into a disk file. In this simple sample, you will learn how to save (record) the drawing instructions and replay them on the screen. Figure 1 shows the running-time snapshot.


    Figure 1-the running-time snapshot for sample 1


    The following indicates the related key code implementation:

    Graphics metagraph=this.CreateGraphics();

    //create a new meta file

    IntPtr hdc =metagraph.GetHdc();

    Metafile metaFile1 = new Metafile("SampMeta1.emf", hdc);

    //use the address of the Metafile object as the drawing plane

    Graphics graphics=Graphics.FromImage(metaFile1);


    //define a red to blue gradient brush

    LinearGradientBrush RtoBBrush=new LinearGradientBrush(

    new Point(0, 10),

    new Point(200, 10),

    Color.Red,

    Color.Blue);

    //define another blue to yellow gradient brush

    LinearGradientBrush BtoYBrush=new LinearGradientBrush(

    new Point(0, 10),

    new Point(200, 10),

    Color.Blue,

    Color.Yellow);

    Pen bluePen=new Pen(Color.Blue);

    //draw a ancient Chinese picture of the Eight Diagrams onto the 'screen'

    Rectangle ellipseRect=new Rectangle(0, 0, 200, 200);

    Rectangle left=new Rectangle(0, 50, 100, 100);

    graphics.DrawArc(bluePen,left,180.0f,180.0f);

    Rectangle right=new Rectangle(100, 50, 100, 100);

    graphics.FillPie(RtoBBrush, ellipseRect,0.0f,180.0f);

    graphics.FillPie(BtoYBrush, ellipseRect,180.0f,180.0f);

    graphics.FillPie(RtoBBrush, left,180.0f,180.0f);

    graphics.FillPie(BtoYBrush, right,0.0f,180.0f);


    //render some text

    SolidBrush solidBrush=new SolidBrush(Color.Black);

    FontFamily fontFamily=new FontFamily("MS Gothic");

    Font font=new Font(fontFamily, 27,

    FontStyle.Regular, GraphicsUnit.Pixel);

    graphics.DrawString("Meta File Test", font, solidBrush,

    new PointF(5.0f, 80.0f));

    //so far, GDI+ has merely store drawing instruction into the harddisk


    //release all the related resources used above

    graphics.Dispose();

    metaFile1.Dispose();

    metagraph.ReleaseHdc(hdc);

    metagraph.Dispose();


    //replay the drawing info created above

    Graphics playbackGraphics=this.CreateGraphics();

    playbackGraphics.Clear(Color.White);

    //open and render the previously-created meta file

    Metafile metaFile2 = new Metafile("SampMeta1.emf");

    playbackGraphics.DrawImage(metaFile2,new Point(0,0));

    //close the open meta file

    metaFile2.Dispose();

    There are two crucial steps in the previous sample. The first step is to create an empty meta file named "SampMeta1.emf,"draw images onto the image, and then render text in it. All of the drawing actions are done on a file in a hard disk-you can see nothing on the screen during the first step.

    The second step picks up from the last few lines. First create a Graphics object, then open the meta file created in the first step and finally, by using the DrawImage() method of the Graphics object, the true rendering plays on the screen. It is only then that you can visualize the rendering result, i.e. replay the meta file on the screen.

    One last word: after running the first sample, you may find a metafile named "SampMeta1.emf," which corresponds to the drawing instructions; without the second step to invoke the DrawImage() method you will not see anything on the screen.

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