Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Create animation in dotNet with alpha-blending PNG images by calling API

0.00/5 (No votes)
6 Jul 2007 2  
This article shows you the advantage of PNG images with alpha-blending feature in creating animation and demonstates how to use PNG images in Framework.NET application by calling API

Sample Image - revolution.jpg

Introduction

A lot of coders (including myself before) have given up working with PNG because it's not so easy to make PNG background image to work smoothly. However, PNG is a very good image format which allows you to use transparency with alpha-blending feature. This article will show you how to make PNG work and the advantage of using it in creating animation.

Secret inside

clsTungPngAnimation inherits the abstract class clsTungAnimation since we intend to have many of the same functions in clsTungPngAnimation and clsTungBmpAnimation. All these classes can be found in clsTungAnimation.cs

frmAnimation.cs (for PNG) and frmBmpAnimation.cs (for BMP) are where picture frames will appear in. If we use PNG, this function must be used to make the form transparent but still can keep alpha-blending of PNG pictures:

protected override CreateParams CreateParams
{
    get 
    { 
        CreateParams cp = base.CreateParams;
        cp.ExStyle |= 0x00080000; //WS_EX_LAYERED    

        return cp;
    }
}

(This function is inside frmAnimation.cs)

clsBitmapTransparent.cs is used to create PNG transparent background for the form.

clsBitmapRegion.cs is used to create a region of a form from loading BMP images so that images will appear transparent.

Trung tam di dong qui tu cac cua hang lon nhat Vietnam

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here