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;
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.