R+D About Mobile Technologies
How to – Fade Algorithms (2)
This is the second article about fade algorithms. In the first article I described the basic algorithm, now I will to introduce you to some advance effects we can do with this basic algorithm.
![]() |
We will use the algorithm MakeFadeRegionToWhite(…) introduced on the post How to – Fade Algorithms (1) to create a new fade effect. This effect can be used, for example, on an initial screen where we usually show the company’s logo.
To create the background effect, we will use the next new algorithm:
| Method Name | |
| MakeMiddleFadeRegion | |
| Parameters | |
| iWidth | Width of the region that we want to fade |
| iHeight | Height of the region that we want to fade |
| iLogoHeight | Height of the logo that will be show |
| iColor | Color to fade |
| bMiddleWhite | If the value is true the color on the middle of the screen will be white |
| Return Value | |
| An int data array with the fade image | |
This is the algorithm:
public static int [] MakeMiddleFadeRegion(int iWidth, int iHeight,int iLogoHeight, int iColor, boolean bMiddleWhite)
{
int [] data1 = MakeFadeRegionToWhite(iWidth, (iHeight - iLogoHeight) / 2, iColor, !bMiddleWhite);
int [] data2 = MakeFadeRegionToWhite(iWidth, (iHeight - iLogoHeight) / 2, iColor, bMiddleWhite);
int [] data = new int[iWidth * iHeight];
int iDiff = data.length - data1.length - data2.length;
for (int i =0 ; i < data1.length ;i++)
{
data[i] = data1[i];
}
for (int i = 0 ; i < iDiff ;i++)
{
data[i + data1.length] = 0x00FFFFFF;
}
for (int i =0 ; i < data2.length ;i++)
{
data[i + data1.length + iDiff] = data2[i];
}
return data;
}
Then we have to use this method in a Canvas Object in this way:
public class MyCanvas extends GameCanvas
{
private Image objFadeImage =null;
private Image objLogoImage =null;
public void paint(Graphics g)
{
iViewH = this.getHeight();
iViewW = this.getWidth();
// create the fade background
if (objFadeImage == null)
{
int [] imgData = Utils.MakeMiddleFadeRegion(iViewW, iViewH,54, 0xd30007,true);
objFadeImage = Image.createRGBImage(imgData, iViewW, iViewH, true);
}
// load the logo
if (objLogoImage == null)
{
try {
objLogoImage = Image.createImage("/res/Logo_150_53.png");
} catch (IOException ex) {
ex.printStackTrace();
}
}
// draw fade background
g.drawImage(objFadeImage,
0,
0,
Graphics.LEFT | Graphics.TOP );
// draw logo
if (objLogoImage != null)
g.drawImage(objLogoImage,
(int)iViewW / 2,
(int)iViewH / 2,
Graphics.VCENTER | Graphics.HCENTER );
}
}
| Print article | This entry was posted by admin on June 26, 2008 at 4:11 am, and is filed under GUI, How To, J2ME, Projects, Technology. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

English
Español