Processing Alpha channels in midp2.0 produces translucent results

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.