Code Examples
  Home arrow Code Examples arrow Page 3 - 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 - Working With Bitmaps


    (Page 3 of 4 )

    By definition, a Bitmap is "a data file or structure representing a generally rectangular grid of pixels, or points of color, on a computer monitor, paper, or other display device." In other words, a bitmapped image corresponds bit by bit to the image displayed on the screen. So a BMP (bitmapped) file stores data in pixel format. GDI+ provides functionalities to manipulate BMP through the Bitmap class which is a derivation of the Image class. Hence, it provides all the functionalities provided by the Image class and adds its own functionalities to work with BMP images. The basic functionalities provided by the Bitmap class are:

    1. Loading the BMP Image
    2. Viewing the BMP Image

    Since the BMP images differ in the way that data is stored (it's pixel based), the way the images are loaded and viewed is also different.

    To load a BMP image, an object of the Bitmap class needs to be created. Such an object can be created using a constructor of Bitmap class in the following ways:

    1. From File:

      In this case, a new Bitmap object is created from an existing file. The existing file can be in any of the GDI+ supported formats. For example, the following code instantiates a Bitmap object from a GIF file:

      Bitmap curBitmap = new Bitmap("myfile.gif");
    2. From an object of Image class:

      A Bitmap object can also be created from an existing image object. Just as with creating an object from a file, all the supported GDI+ formats based on the Image object can be used. The following code creates a Bitmap object from an Image object which in turn is created from a GIF file:

      Image curImage = Image.FromFile("myfile.gif");
      Bitmap curBitmap = new Bitmap(curImage);
    3. From an object of the Image class with a specified size:

      This is the specialized form of the previous method. In this case, the object being created can be assigned dimensions (width and height) at the time of instantiation. The following statement illustrates this point:

      Bitmap curBitmap3 =new Bitmap(curImage, new Size(200, 100) );
    4. An empty Bitmap object:

      When no Image reference or file name is provided, an empty Bitmap object is created. The following statement does the same:

      Bitmap curBitmap = new Bitmap(200, 100);

    Apart from the constructor, the Bitmap class provides two static methods that can be used to create BMP from icons (.ico files) and resources (.res files). They are FromHicon and FromResource. Both use handles to icons or resources to create a Bitmap object from icons and resources. That completes the ways to load BMP. Next we'll see what we need to do to view the loaded BMP.

    Viewing BMP Image using the Bitmap class is just like viewing any other image using the Image class. Once the Bitmap object is created, it has to be passed to the DrawImage method. The following code illustrates this point:

    Graphics g = this.CreateGraphics();
    Bitmap bitmap = new Bitmap("myfile.jpg");
    g.DrawImage(bitmap, 20, 20);
    g.Dispose();

    That completes this section. In the next section I will enhance the image viewer application to include a GIF animation control menu.

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