Code Examples
  Home arrow Code Examples arrow Page 4 - Handling Animations and Bitmaps Using 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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
CODE EXAMPLES

Handling Animations and Bitmaps Using GDI+ for Image Manipulation
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 19
    2007-03-20

    Table of Contents:
  • Handling Animations and Bitmaps Using GDI+ for Image Manipulation
  • Playing with Animation: StopAnimate and UpdateFrame
  • Working With Bitmaps
  • Image Animation in the Real World

  • 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


    Handling Animations and Bitmaps Using GDI+ for Image Manipulation - Image Animation in the Real World


    (Page 4 of 4 )

    Now let's implement the animation control into the application that was being built during previous parts of this series. The enhancements will provide the following functionalities:

    1. Start the animation if the GIF contains time based frames.
    2. Stop the animation.

    The following are the menus that correspond to the functionalities:

    1. mnuAnimationStart
    2. mnuAnimationStop

    The handler for the mnuAnimationStart is as follows:

    private void mnuAnimationStart_Click(object sender,
    System.EventArgs e)
    {
      
    curImage = Image.FromFile(curFileName);
      
    if( ImageAnimator.CanAnimate(curImage) )
      
    {
        
    ImageAnimator.Animate(curImage,
        
    new EventHandler(this.OnFrameChanged));
      
    }
      
    else
        
    MessageBox.Show("Image doesn't have frames");
    }

    The handler first checks whether the image can be animated or not. Then it calls the Animate method.

    The code for the mnuAnimationStop handler is as follows:

    private void mnuAnimationStop_Click(object sender,
    System.EventArgs e)
    {
       if(curImage != null)
       {
         ImageAnimator.StopAnimate(curImage,
    new EventHandler(this.OnFrameChanged));
       }
    }

    Add the following code to the OnPaint :

    if(curImage != null)
    {
      if( ImageAnimator.CanAnimate(curImage) )
     
    {
       
    ImageAnimator.UpdateFrames();
     
    }
    }

    Here I am checking whether or not the image contained in the curImage object has frames, because the rendering of other images also happens in OnPaint.

    And here is the event handler referenced by the Animate and StopAnimate methods:

    private void OnFrameChanged(object o, EventArgs e)
    {
       this.Invalidate();
    }

    Whenever the animation has to be started or stopped (in other words, the next frame has to be rendered), OnFrameChanged is called internally by the Animate and StopAnimate methods, which in turn invalidate the current drawing region.

    This brings us to the end of the discussion on animation control and the basics of handling BMP files. In the next part I will discuss advanced aspects of BMP images and other image manipulation techniques such as skewing. Till then...


    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.

       · In this artocle I have discussed about handling animated gif and basics of bitmap...
     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





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