Semi-transparent effects are often used in games. However, in the midp1.0 era, only the extended APIs of Nokia and LG provided APIs that can process Alpha channels. In midp2.0, we can use the method provided by the image class to obtain a translucent version of the image.
Try {
Image = image. createimage ("/ken.png"); // load the source Image
}
Catch (ioexception e ){}
Int [] argb = new int [image. getwidth () * image. getheight ()]; // generates an array of image data
Image. getrgb (argb, 0, image. getwidth (), image. getwidth (), image. getheight (); // obtain the argb matrix.
For (INT I = 0; I <argb. length; I ++ ){
Argb [I] & = 0xa0ffffff; // set the alpha channel value of each pixel to A0. The correct method is not to change the transparent pixel points whose original Alpha value is 0.
}
Image1 = image. creatergbimage (argb, image. getwidth (), image. getheight (), true); // generate a new image
The running effect is as follows:
In this way, translucent effects can be achieved in the game. With your creative talents, the game will surely become more dazzling!
This program passed the test under eclipse3.0 + eclipseme0.6 + wtk2.2.