lukew 发表于 2013-1-27 04:43:20

Fade in and out images in MIDP 2.0

This tip describes how to change the alpha value of an image to make itappear blended. There's also an example MIDlet with source code.

In MIDP 2.0 there's a new method in the Image class, getRGB(...)that will get all Alpha, Red, Green, Blue (ARGB) values from the imageto an int array. We can use this method, and the resulting array, tochange the alpha value of the image.

Integers in J2ME are four bytes, each pixel in the image is describedby the ARGB values where each color is one byte 0 to 255. If the alphavalue is 0, the corresponding pixel will be transparent, if the alphais 255, the pixel will be opaque.

To get a specific color from the int array, it's possible to use the AND '&' operator and to accomplish the blending effect we need to get the colors, without the alpha value, from the int array.
<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!---->FF = 11111111 = 255
0xFFFFFFFF - Alpha = 255, Red =255 Green = 255, Blue = 255
(0xFFFFFFFF & 0x00FFFFFF) = 0x00FFFFFF

页: [1]
查看完整版本: Fade in and out images in MIDP 2.0