Code Examples
  Home arrow Code Examples arrow 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


    (Page 1 of 4 )

    Among all the formats of image files, GIF (Graphic Interchange Format) and BMP occupy a special place. GIF can support animation, while BMP's bitmapped nature sets it apart. GDI+ provides APIs to control the animation contained in a GIF as well as manipulate the bitmaps in a BMP.

     In this discussion I will focus on controlling animated GIF and the basics of manipulating BMP images using GDI+. The first and section sections will concentrate on the animated GIF and the APIs for controlling it. The third section will cover working with bitmapped images. Finally, in the fourth section I will  enhance the application developed in the previous part by adding the functionality to play animations when the selected image is an animated GIF. That's the agenda for this discussion.

    This article is the third part of a series. The reader may benefit from reviewing the first two parts, Basic Image Manipulation Using GDI+ and C# and Thumbnails and Zooming with GDI+ and C#.

    Playing with Animation: CanAnimate and Animate

    By definition, "Animation is the rapid display of a sequence of 2-D artwork or model positions in order to create an illusion of movement." The articles I have written until now dealt with the manipulation of static images.

    There are formats that can hold data for animation. These are AVI, MPEG, GIF and others. The images in these formats are known as animated images, as in the animated GIF. Animated images hold three kinds of data: images that have to be used, known as frames, and the order as well as the interval between the frames.

    Though there are multiple formats that can handle animation, GDI+ currently supports multi-frames only in TIFF and GIF. Out of these I will concentrate solely on GIF. The following are the APIs provided by GDI+ for the animated GIF through the ImageAnimator class :

    1. CanAnimate
    2. Animate
    3. StopAnimate
    4. UpdateFrames

    All of these methods are static. GDI+ doesn't provide any support for the creation of animated images. In this section and the next I will focus on each of these methods in turn.

    CanAnimate is the first method that needs to be called to ensure that the image can be animated. It returns true if the image contains time-based frames. This method takes the reference of the image to be tested for time-based frames as an argument. The point to remember is that any animated image will contain time based frames. If the time-based frames are not there, it is a static image. When a static image is given as an argument, false is returned by the method.

    For example, the following code checks for the animation capability of an image:

    curImage = Image.FromFile(curFileName);
    if( ImageAnimator.CanAnimate(curImage) )
    {
      //logic for animating the image
    }
    else
      MessageBox.Show("Image doesn't have frames");

    Once it has been determined that an image contains time-based frames, then its animation can be controlled by controlling the frames. The Animate method is invoked to accomplish this goal. It takes two arguments, an image and an event handler. The image refers to the current image and the event handler is called when the frame changes. In other words, the Animate method controls the animation by triggering the event handler passed as an argument on the change of frames within the passed image parameter. In code it would be:

    if (!currentlyAnimating) {
      //Begin the animation only once.
      ImageAnimator.Animate(animatedImage, new EventHandler(this.OnFrameChanged));
      currentlyAnimating = true;
    }
    private void OnFrameChanged(object o, EventArgs e) {
      //Force a call to the Paint event handler.
      this.Invalidate();
    }

    In the above example, the Animate method is given two parameters. These are the animatedImage, which is the image to be animated, and an event handler referenced by this.OnFrameChanged. The handler invalidates the current rendered image to draw the new frame, thus providing an "animation."

    More Code Examples Articles
    More By A.P.Rajshekhar


       · 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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek