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






3.87/5 (94 votes)
Oct 19, 2005

107824

7341
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
- Download source files - 153 Kb
- Download demo project - 86 Kb
- Download PNG source files - 120 Kb
- Download PNG demo project - 116 Kb
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.